precise的Filesmatch指令的目标 [英] Precise targeting of the Filesmatch directive

查看:271
本文介绍了precise的Filesmatch指令的目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找我的网站的根index.html文件切换到index.php文件的最好方法。我的研究表明,这样做不慎将导致命中我在谷歌的排名,而我最好的选择是解析索引文件如PHP,并指出,这是在哪里预计需要这种解析该网站的唯一文件。

I have been looking for the best way to switch my website's root index.html file to a index.php file. My research indicates that doing this carelessly will result in a hit to my rankings in Google and that my best option is to parse the index file as php, noting that this is the only file on the site where such parsing is anticipated to be needed.

我看了非常大,所以在这里跟帖:解析HTML为PHP 这是在非常有用这个题目,我决定使用的Filesmatch指令做到这一点在我的.htaccess文件。但是最好的回应presented有恕我直言,是其中一个建议如下code。

I read a great SO thread here: Parse HTML as PHP which was very useful on this subject and I am settled on using the Filesmatch directive to do this in my .htaccess file. However the best response presented there IMHO was one which suggested the following code.

<FilesMatch "^file_name\.html$">
AddType application/x-httpd-php .html
</FilesMatch>

我当然实现这个为:

I of course implemented this as:

<FilesMatch "^index\.html$">
AddType application/x-httpd-php .html
</FilesMatch>

虽然这只是正常的根index.html页面,所有网站的子目录还有的index.html页,事实证明,他们都得到解析为PHP了。为了安全,我不希望这种行为。我不是一个Apache亲和我得到了我的深度,这里一点,因此要求你们。有没有办法阻止这一点,使根索引文件的唯一一家通过此Filesmatch指令的目标?谢谢你。

While this works just fine for the root index.html page, all the site's sub-directories also have index.html pages and it turns out that they are all getting parsed as php too. For security, I don't want this behaviour. I am not an Apache pro and am getting out of my depth a little here hence asking you guys. Is there a way to stop this and make the root index file the only one targeted by this Filesmatch directive? Thank you.

推荐答案

而不是解析 /index.html 为PHP文件为什么不直接使用 301(永久重定向) /index.html 的index.php 根的.htaccess使用下面的规则

Rather than parsing /index.html as a PHP file why not just use 301 (permanent redirect) from /index.html to /index.php using following rule in root .htaccess:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/index\.html [NC]
RewriteRule ^index\.html$ /index.php [L,R=301,NC]

这篇关于precise的Filesmatch指令的目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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