htaccess的删除HTML扩展后永久重定向 [英] Permanent redirect after removing html extension in htaccess

查看:193
本文介绍了htaccess的删除HTML扩展后永久重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些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]

这篇关于htaccess的删除HTML扩展后永久重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆