2013-11-27 42 views
3

我的.htaccess文件中有以下代码。将所有请求重定向到没有直接访问的index.php

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] 

这将所有请求重定向到index.php。不过,我仍然可以直接从URL访问www.mydomain.com/index.php。由于www.mydomain.com服务器与www.mydomain.com/index.php服务器的内容相同,这将记录为在谷歌重复,如果是的话,我该如何防止它。

回答

3

插入现有的规则之前,此规则从URI删除index.php

RewriteCond %{THE_REQUEST} /index\.php [NC] 
RewriteRule ^(.*?)index\.php$ /$1 [L,R=301,NC,NE] 
+0

这是工作。我会在5分钟内接受它。谢谢.. – codeGEN

+0

不客气,很高兴它为你解决。 – anubhava

相关问题