Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i have multiple naked domains and i want to redirect those domains so that they begin with www.redirecteddomain.com. i have this .htaccess file which works with on domain how to generalize this ?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^guvam\.com$
RewriteRule (.*) http://www.guvam.com$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
share|improve this question

migrated from stackoverflow.com Dec 18 '10 at 3:10

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

I don't quite understand the question, but you want it to work for any domain to direct to the www. version?

This should work for that:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]+\.[^\.]+)$
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
share|improve this answer
add comment

I find this slightly more readable

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.