htaccess 重写规则未按预期工作



我有以下规则:

RewriteRule ^(.*)$ index.php?ip=$1 [L]

但它不起作用,而是正在加载:

https://example.com/?ip=index.php

我错过了什么吗?

您的规则正在循环,因为没有条件停止重写现有文件和目录。

第一次重写后,它变成:

index.php?id=1.2.3.4

第二次重写后,URI 变为:

index.php?id=index.php

您可以使用此规则来修复此行为:

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?ip=$1 [L,QSA]

最新更新