的.htaccess - 301重定向没有扩展名的文件有.html扩展 [英] .htaccess - 301 redirect all files without extension to have .html extension

查看:112
本文介绍了的.htaccess - 301重定向没有扩展名的文件有.html扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要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扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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