using .htaccess to append .html behind url path

我们两清 提交于 2019-12-25 02:19:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!