0

So I have pages like:

/features.html

I want to link to this page as just

/features

RewriteEngine on
RewriteRule ^(.*)$ *PATH*.html

The text *PATH* should take the folder path and append .html to it, EXCEPT if the path ends in /

1 Answer 1

0

Following your logic, you'd arrive at:

RewriteEngine on
#If path ends in a forward slash, don't rewrite
RewriteRule ^(.*)/$ - [L]
#If path ends in .html, don't rewrite (avoiding an infinite loop)
RewriteRule ^(.*)\.html$ - [L]
#Otherwise add .html to the end (note this will apply to images too)
RewriteRule ^(.*)$ $1.html

But that will affect other extensions as well such as images. I'd suggest checking if the file exists or not instead like so:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ $1.html
1
  • Yes, I found straight away images/css/jss weren't loading! :-) Jul 25, 2016 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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