Rewrite rule to add .html suffix

北慕城南 提交于 2019-12-24 11:21:42

问题


I am using WordPress. I need to add a custom rewriterule. I want to have two URLs for a single page.

For example:

www.test.com/abc <--- At present this is implemented & working fine.

www.test.com/abc.html <--- Need to add .html at back side.

I want to allow access to the same page with .html extension.

How can I do that?


回答1:


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]

Feel free to drop the L flag, if it's not the last rewrite rule. See RewriteRule Flags for more information on this.

You can test it online:



来源:https://stackoverflow.com/questions/41298005/rewrite-rule-to-add-html-suffix

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