问题描述
我需要301请求重定向到文件不带扩展到相同的附加.html扩展名:
I need to 301 redirect requests to files with no extension to same with appended .html extension:
http://www.mydomain.com/this
到
http://www.mydomain.com/this.html
下不会重定向:
The following would not get redirected:
http://www.mydomain.com/that/ (it's a directory)
http://www.mydomain.com/other.php
pciated以上,感谢任何帮助AP $ P $。
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]
这应确保该请求是不是一个目录,这是不是结束的某种扩展的。如果这些条件得到满足,将追加的要求的.html
。
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. ;)
这篇关于的.htaccess - 301重定向没有扩展名的文件有.html扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!