Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I keep getting variations of the following answer, and it doesn't work

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

The reason this solution is no good is that if I go to

alwaysromaing.com/site

I'll never get be redirected to the WWW.alwaysroaming.com/site

Can anyone provide the correct rewrite required here?

share|improve this question

closed as off topic by ChrisF, Ƭᴇcʜιᴇ007, Sathya Jun 2 '11 at 4:53

Questions on Super User are expected to relate to computer software or computer hardware within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

4  
Already answered at length, for rewriting in both directions, on ServerFault and StackOverflow over and over and over and over and over and over and over and over and over again. –  JdeBP Jun 1 '11 at 12:57
    
Wow man I had to plus one your comment as it is amazing how much effort you put into that, finding all of them and linking them like that. Love it! –  Jason Jun 2 '11 at 1:08

2 Answers 2

I'd suggest this:

RewriteCond %{HTTP_HOST} !^www.alwaysroaming.com$ [NC]
RewriteRule ^/(.*)$ http://www.alwaysroaming.com/$1 [R=301,L]

The key part is the '/' after the '^' in the second line. The NC in means it'll work if someone types in mixed/upper case.

share|improve this answer

This is such a common question that it's part of the documentation for mod_rewrite - which you did read, right?

Assuming you're running on port 80:

RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://fully.qualified.domain.name/$1 [L,R]

the documentation has another example in case you're not on port 80, and covers other common scenarios

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.