htaccess重写规则无法正常工作

时间:2017-08-13 06:00:35

标签: .htaccess

我有以下规则:

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

但是它无法正常工作,而是正在加载:

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

我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

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

首次重写后,它变为:

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]