Forum Moderators: phranque
my code:
RewriteEngine On
RewriteBase /
#
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
#
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule ^(([^/]+/)*[^./]+)$ /$1.html [R=301,L]
Any help would be appreciated.
,L to the [R=301] on the first rule, making it into [R=301,L]. Remove the
R=301 from the last rule to change it from a redirect into being a rewrite. Use only [L] there. Additionally
RewriteBase / is the default and can be removed. Finally,
^(.*)$ simplifies to (.*) here. You also need to link to the URLs you want users to 'see' from within the pages of your site.
You were very close! That's one of the best "first tries" posted into the forum in recent weeks.
You will also need to set up a 301 redirect such that if anyone asks for a .html URL they are redirected to the correct URL. Force www within the same redirect for those requests too. That new, extra, redirect code goes before your existing non-www to www redirect code.
RewriteEngine On
#
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule ^(([^/]+/)*[^./]+)$ /$1.html [L]
I still must be doing something wrong, because example.com/page still changes to www.example.com/page.html instead of www.example.com/page