我有以下规则:
RewriteCond %{REQUEST_URI} !script.php
RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule .* script.php?q=%1
RewriteCond %{REQUEST_URI} !script.php
RewriteRule (.*) script.php?q=$1我在这里试图完成的是,对http://example.com/?url=www.google.com的每一次访问都被重定向到script.php?q=www.google.com,如果没有查询字符串,则应该将相对路径发送到script.php,例如在http://example.com/path中,应该将其重定向到script.php?q=path。这似乎不符合我的规则,但我不知道为什么。这有可能吗?
发布于 2014-10-26 13:41:05
你可以有这样的规则:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^url=([^&]+) [NC]
RewriteRule ^/?$ script.php?q=%1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.+)$ script.php?q=$1 [L,QSA]https://stackoverflow.com/questions/26573188
复制相似问题