【发布时间】:2020-11-17 21:15:11
【问题描述】:
以前由于不正确的 .htaccess 逻辑,我的许多 http://example.com/path/ url 被重定向到 https://example.com/index.php?/path/
所以有很多页面被谷歌抓取到https://example.com/index.php?/path/
我正在使用 codeigniter,我不想在我的 URL 中使用 index.php,所以我有从 URL 中删除 index.php 的重写规则,所以下面是重写规则。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
但是由于 Google 已经在 URL 中使用 index.php 抓取了许多页面,我想将这些 URL 重定向到没有 index.php 但这会产生冲突并创建无限重定向,一个删除然后一个添加,然后开。
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)index\.php https://example.com%1? [R=302,L]
所以当我访问 example.com/path/ 时,这会导致“重定向过多”问题。
我的逻辑在这里卡住了。
我该怎么办?
【问题讨论】:
-
你把它放在哪里,在现有的重写之上还是之下? (你到底想在
index.php之前与(.*)匹配什么?) -
@CBroe 嗨,我已经把现有的放在下面,但我尝试移到顶部,没有区别。对于 (.*),最初我以为可能有一些 url example.com/path/index.php?/path2/ 但是现在我总是在一开始就意识到,我猜 index.php 之前的 (.*) 是不必要的。
标签: apache .htaccess codeigniter mod-rewrite url-rewriting