I have a redirect situation where the site is part dynamic and part generated .html files.

For example, mysite.com/homepage and mysite.com/products/42 are actually static html files

Whereas other URLs are dynamically generated, like mysite.com/cart

Both mysite.com and www.mysite.com are pointing to the same place. However I want to redirect all of the traffic from mysite.com to www.mysite.com.

I'm so close but I'm running into an issue where Apache is adding .html to the end of my URLs for anything where a static .html file exists - which I don't want.

I want to redirect this:


To this:


But Apache is making it this, instead (because 42.html is an actual html file):


I don't want that - I want it to redirect to www.mysite.com/products/42

Here's what I started with:

RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]

RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

I tried making the parameters and the .html optional, but the .html is still getting added on the redirect:

RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]

RewriteRule ^(.*)?(\.html)?$ http://www.mysite.com/$1 [R=301,L]

What am I doing wrong? Really appreciate it :)

  • How are the static HTML files being served if the request doesn't include ".html"? Are there other rewrite rules which add the ".html" and are interfering with this? – mgorven Mar 26 '12 at 22:51

I blame MultiViews!

Try setting Options -MultiViews to disable the extension-guessing behavior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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