问题
People are coming into my website like this:
sitename.com/brands/brandA
But this will cause an 404 error because I actually need them to come to this url
sitename.com/brands/brandA.html
How can I append the .html extension automatically when needed when someone enters sitename.com/brands/*
with no .html extension using the .htaccess
document.
回答1:
why don't you try this.
RewriteEngine On
RewriteRule ^/brands/(.*)$ /brands/$1.html [L]
回答2:
You can use mod_negotiation for this, too:
<IfModule mod_negotiation.c>
Options +MultiViews
</IfModule>
If a request comes in, that would result in a 404, mod_negotiation takes other headers like the Accept
into account and looks for files with the same base name but appropriate extensions.
来源:https://stackoverflow.com/questions/7751329/using-htaccess-to-append-html-behind-url-path