Welcome to WebmasterWorld Guest from 54.144.24.41

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Looking for .htaccess rewrite code to add www - but for any domain

     
5:30 pm on Jan 24, 2006 (gmt 0)

New User

10+ Year Member

joined:Jan 24, 2006
posts:3
votes: 0


Hi. I have seen lots of examples of .htaccess rewrite code that will redirect any mydomain.com requests to www.mydomain.com. However I would like an example where one doesn't have to code the actual domain name, as I have a single script installation being used by many web sites, and therefore cannot hard code the domain name in the .htaccess file.

Does anyone have an example?
Thanks

7:08 pm on Jan 24, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 21, 2006
posts:82
votes: 0


Here.
[webmasterworld.com...]

If you only need it for http, this should do.


Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST}!^(www\.¦$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This code takes care of missing trailing slash problem, too.


Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI}\\/%{HTTP_HOST}/www. ^/+(.+/)?[^.]*[^/]\\(/)([^w][^w][^w][^.].*/(www\.)¦.*)$ [OR,NC]
RewriteCond %{HTTP_HOST}/www. ^(/)?(/)?([^w][^w][^w][^.].*/(www\.))$ [NC]
RewriteRule ^ http://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]
10:22 am on Jan 25, 2006 (gmt 0)

New User

10+ Year Member

joined:Jan 24, 2006
posts:3
votes: 0


extras, many thanks, that is perfect.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members