I have a .htaccess file on my main directory on my website, which basically allows pretty urls (example.com/index
instead of example.com/index.html
) and it will redirect to a pretty url if someone goes to example.com/index.html
.
Here is the code that I use for this:
#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
The issue is that I have a sub domain on the website, forum.example.com/
and when I click on a link on the page, it will go to forum.example.com/forum/page/
which goes to a 404 error page, since it should be http://forum.example.com/page/
I suppose I could delete the 301 redirect in my .htaccess file, but I would like to keep that, as it makes the website look nicer.
.html
3. Why are you using%THE_REQUEST
which should be a string likeGET /index.html HTTP/1.1
? I'd expect you to use%{REQUEST_FILENAME}
there as well. – Stephen Ostermiller♦ Feb 17 at 23:16