.htaccess - 将所有请求重定向到 index.php 而无需直接访问

标签 .htaccess redirect

我的 .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/

相关文章:

drupal - 当安装位于关联的子目录中时,如何从 Drupal 7 中的 URL 中删除/drupal

php - 将完整的 wordpress 站点转换为 HTTPS

linux - FastCGI with perl - 在共享 Linux 虚拟主机上

node.js 请求获取重定向链

jsf - 如何在 JSF 中导航?如何使 URL 反射(reflect)当前页面(而不是上一页)

linux - 在 .htaccess 中使用空格访问环境变量

python - 重定向的 URL 列表比较

javascript - 为什么 window.location 不加载新页面?

.htaccess - 添加 www.删除 .html

javascript - 在 iPhone 上查看完整网站,而非手机版