我想重写一个类似http://www.domain.tld/test/page.html?id=1&required=1&foo=bar
的URL至http://www.domain.tld/wrapper.php?url=[FULL REQUEST URL]
在wrapper.php中,我希望$_GET['url']
是http://www.domain.tld/test/page.html?id=1&required=1&foo=bar
到目前为止我尝试过的:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*required=.*)$ [NC]
RewriteRule ^ /wrapper.php?url=http://%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING} [L]
但不幸的是,$_GET['url']
现在只是http://www.domain.tld/test/page.html?id=1
,缺少其他参数。
正确的apachesynthax应该是什么样子?
尝试将QSA添加到重写规则
[L,QSA]
您可以在根目录中使用这样的规则。htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)required=[^&]+ [NC]
RewriteRule !^wrapper'.php /wrapper.php/http://%{HTTP_HOST}%{REQUEST_URI}@%{QUERY_STRING}? [L,NC]
RewriteCond %{REQUEST_URI} ^(/wrapper'.php)/([^@]*)@(.+)$ [NC]
RewriteRule ^ %1?url=%2'?%3 [L,B]