Www or not with .htaccess

I have a problem… When typing www.mysite.com/test my site messes up, but if I type mysite.com/test everything is just fine… I think it is in my .htaccess file, but cant figure out where…

RewriteRule ^test/([a-zA-Z0-9_-]+)/?$ index.php?id=$1

Not sure this is the right forum, but please help…

Your RewriteRule doesn’t catch www.yourdomain.com/test
It minimally catches www.yourdomain.com/test/ (note the trailing slash).

In order to answer your question, could you please

  1. Describe exactly what’s going wrong?
  2. Post the complete .htaccess file?

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

Good eyes, XTX!

jmansa and hash,

I have the force www and remove www code in the tutorial linked in my signature which will work on both Apache 1.x and Apache 2.x (hash, yours will not work on Apache 1.x because of the double // after the domain).

Now, as XTX asked: What is your mod_rewrite? What is your test URL?

Regards,

DK

I solved it by going the other way around…

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

Thanks…

jmansa,

Hmmm, I see that you are NOT testing for case INsensitive domain. Is there a reason to allow MySite.com to pass through without being redirected to the www’d version?

Are you CERTAIN that you’re using Apache 2.x?

While I’m glad that you’re satisfied with your solution, I hope others do NOT use your example as guidance for those two omissions.

Regards,

DK