重写规则以添加.html后缀 [英] Rewrite rule to add .html suffix
本文介绍了重写规则以添加.html后缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用WordPress.我需要添加一个自定义重写器.我想在一个页面上有两个URL.
I am using WordPress. I need to add a custom rewriterule. I want to have two URLs for a single page.
例如:
www.test.com/abc < ---目前已实现&工作正常.
www.test.com/abc <--- At present this is implemented & working fine.
www.test.com/abc.html < ---需要在背面添加.html.
www.test.com/abc.html <--- Need to add .html at back side.
我想允许访问扩展名为.html
的同一页面.
I want to allow access to the same page with .html
extension.
我该怎么做?
推荐答案
我通过注释进行解释.
I explain through comments.
RewriteEngine on
RewriteBase /
# Make sure it's not an actual file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Make sure the hostname is www.test.com
RewriteCond %{HTTP_HOST} ^www\.test\.com
# If the request matches "abc.html", rewrite to abc
RewriteRule ^abc\.html$ abc [L,QSA]
# If you need to make this a generic rule, try this instead:
#RewriteRule ^(.*)\.html$ $1 [L,QSA]
如果不是最后一个重写规则,请随意删除L
标志.有关更多信息,请参见 RewriteRule标志.
Feel free to drop the L
flag, if it's not the last rewrite rule. See RewriteRule Flags for more information on this.
您可以对其进行在线测试:
这篇关于重写规则以添加.html后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文