Top Poster
#1 ramon fincken 400
#2 Site admin 3
#3 Ber|Art 2
#4 braddmark 1
#5 accentmedia 1
#6 Xarzu 1
#7 pEcosespedex 1
#8 khadish 1
#9 moxxx 1
#10 nistelrock 1
[solution] Adding "www." in front of your domain using htaccess rewrite rules ( modrewrite ) force



Rating : 4.6 / 5

 
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> PHP coding
Beta
Want to be notified by email when this topic gets a reply?  
View previous topic :: View next topic  
Author Message
ramon fincken
Site's programmer

Get a free globally recognized avatar
It's free!


Joined: 03 Aug 2007
Posts: 400
Location: A'dam/Diemen, The Netherlands

PostPosted: Mon Jul 07, 2008 8:01 pm    Post subject: [solution] Adding "www." in front of your domain using htaccess rewrite rules ( modrewrite ) force Reply with quote

Allright, if you require to have a "www." in front of your domain name at all times add this to your htaccess file:


Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.ramonfincken\.com$ [NC]
RewriteRule ^(.*)$ http://www.ramonfincken.com/$1 [R=301,L]



It completely rewrites ( click to see in action ! )
http://ramonfincken.com to http://www.ramonfincken.com
and also
http://ramonfincken.com/?foo=bar to http://www.ramonfincken.com/?foo=bar

Read on:
http://www.askapache.com/htaccess/mod_r...write-hint
http://yoast.com/how-to-remove-www-from...d_rewrite/
Back to top
View user's profile Send private message Visit poster's website
Google adsense
Advertisement





PostPosted: Mon Jul 07, 2008 8:01 pm    Post subject: [solution] Adding "www." in front of your domain using htaccess rewrite rules ( modrewrite ) force

Advertisement
Back to top
GravityForms
Advertisement





PostPosted: Mon Jul 07, 2008 8:01 pm    Post subject: [solution] Adding "www." in front of your domain using htaccess rewrite rules ( modrewrite ) force

Advertisement
Gravity Forms Plugin for WordPress
Back to top
Site admin
Site Admin

Get a free globally recognized avatar
It's free!


Joined: 03 Aug 2007
Posts: 3

PostPosted: Wed Sep 05, 2012 12:19 pm    Post subject: Re: [solution] Adding "www." in front of your domain using htaccess rewrite rules ( modrewrite ) force Reply with quote

Even better, for all names:

Code:
RewriteEngine On
RewriteBase /
# non empty HTTP_HOST in the request
RewriteCond %{HTTP_HOST} !^$ [NC]
# does not start with 'www'
RewriteCond %{HTTP_HOST} !^www\. [NC]
# saves the value of HTTP_HOST in %1
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
# redirects using the saved URI (in RewriteRule) and saved hostname (in the last RewriteCond)
RewriteRule ^(.*)$ "http://www.%1/$1" [L,R=301]
# that's it !


source:
http://drupal.org/node/93603
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> PHP coding All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
General forums
The world of freelance
Programming
Other projects
Poll
I love gifts

Yes goodies and presents! [3]
No but I love polls ! [1]

Related google ads