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 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:

  http://mysite.com/products/42 

To this:

  http://www.mysite.com/products/42

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

  http://www.mysite.com/products/42.html

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 :)

share|improve this question
    
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

1 Answer 1

I blame MultiViews!

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

share|improve this answer

Your Answer

 
discard

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

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