Forum Moderators: phranque
I've been trying to achieve the following:
- Rewrite non www requests to www prefixed ones
- Disable access to .html files and maybe redirect to an address that doesnt show the extension
- Internally rewrite requests without extension to .html requests so that the file is called properly
The code works for requests to http://example.org but not for www.example.org. Hope someone can help.
Thx.
----- START
RewriteCond %{HTTP_HOST} !^www\.example\.org$
RewriteRule ^ http://www.example.org%{REQUEST_URI} [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]+\.html [NC]
RewriteRule \.html$ - [F,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f [NC]
RewriteRule .* $0.html [L]
----- END
The code works for requests to http://example.org but not for www.example.org.
"It doesn't work for www.example.org" is not a very informative statement...
Please describe how you tested, including test URLs, what the desired results were, what the actual results were, how those results differed from your expectations, and include any relevant entries from your server error log.
Also, be sure you completely flush your browser cache before testing any changes to your configuration.
Jim
example.org/test --> http://www.example.org/test.html
Acces denied. NOT OK.
example.org/test.html --> http://www.example.org/test.html
Access denied, OK.
http://www.example.org/test --> http://www.example.org/test
File "test.html" is displayed. OK.
http://www.example.org/test.html --> http://www.example.org/test.html
Access denied, OK.
Why access denied on the first one, should redirect to http://www.example.org/test and display the file.
And why ".html" ?
RewriteCond %{HTTP_HOST} !^www\.example\.org$
RewriteRule ^ http://www.example.org%{REQUEST_URI} [L,R=301]
#
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[b][^.?\ ][/b]+\.html [NC]
RewriteRule \.html$ - [b][F,NC][/b]
#
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html [b]-f[/b]
RewriteRule [b](.*) /$1[/b].html [L]
Be sure that your custom 403 error page (if you have one) does not end with ".html". If it does, you will have to explicitly exclude it from your second rule.
Jim