开发者

.htaccess - 301 redirect all files without extension to have .html extension

I need to 301 redirect requests to files with no extension to same with appended .html extension:

http://www.mydomain.com/this

to

http://www.mydomain.com/this.html

The following would not get redirected:

http://www.mydomain.com/开发者_Python百科that/ (it's a directory)
http://www.mydomain.com/other.php

Any help appreciated on the above, thanks.


Try the following. I would place it as the last rule in your set (i.e. the bottom) to not conflict with any other rules.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\..+$
RewriteRule ^(.*)$ /$1.html [R=301,L]

This should ensure the request is not a directory and that is doesn't end with some kind of extension. If those conditions are met, it will append the request with .html.

This is untested, so comment back if it works. ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜