htaccess的删除HTML扩展后永久重定向重定向、htaccess、HTML

由网友(說ぬの緈諨呢)分享简介:我有这些htaccess的规则,以消除HTML扩展,从网址:I have these htaccess rules to remove html extension from urls:RewriteEngine OnRewriteBase /RewriteCond %{REQUEST_FILENAME} !-...

我有这些htaccess的规则,以消除HTML扩展,从网址:

I have these htaccess rules to remove html extension from urls:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html

它工作正常,但我仍可以从带扩展名的URL来访问。如何让这个当用户点击链接与扩展,将与一个永久(301)重定向重定向到扩展名的URL?

It works fine but I can still access from the URL with extension. How to make it so that when a user click the url with extension, will be redirected with a permanent (301) redirect to the extensionless url?

感谢

推荐答案

就在年底这表明它是一个301重定向添加小片段。

Just add the little snippet at the end which indicates it is a 301 redirect.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [R=301,L]
阅读全文

相关推荐

最新文章