Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm having a bad .htaccess day!

I want a user to be able to type the URL

mysite.com/about

instead of

mysite.com/about.html

On .htaccess file I have:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/(.*)$ /$1.html [NC,L]

But this simply does not work?

I will add though that if i try this further inside the site e.g.

mysite.com/pages/contact

Works perfectly whether I have the above code in the .htaccess or not

What am I doing wrong?

share|improve this question

migrated from stackoverflow.com Mar 31 '12 at 23:35

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

    
Not a direct solution, but moving the file to about/index.html gives you the same result. –  johannes Mar 30 '12 at 12:42
1  
There should be NO leading slash when matching in RewriteRule if placed in .htaccess. Try this: RewriteRule ^(.*)$ /$1.html [NC,L] –  LazyOne Mar 30 '12 at 12:50
    
Also, instead of using mod_rewrite, you can look at Options directive, MultiViews in particular: httpd.apache.org/docs/current/mod/core.html#options –  LazyOne Mar 30 '12 at 12:53
add comment

1 Answer

up vote 3 down vote accepted

just avoid slashes before both matching patterns and destination. So,

RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [NC,L]

should work perfectly.

share|improve this answer
add comment

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.