我的 .htaccess 文件中有以下代码。
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 的内容相同,这将在谷歌中被记录为重复,如果是这样,我该如何防止它。
最佳答案
在现有规则之前插入此规则以从 URI 中删除 index.php
:
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=301,NC,NE]
关于.htaccess - 将所有请求重定向到 index.php 而无需直接访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20239304/