通过.htaccess将URL参数传递到php文件
我需要通过.htaccess将URL和所有参数一起传递到其他php文件中。例如: URL:通过.htaccess将URL参数传递到php文件,php,apache,.htaccess,url-rewriting,Php,Apache,.htaccess,Url Rewriting,我需要通过.htaccess将URL和所有参数一起传递到其他php文件中。例如: URL:abc.com/article/test1/test2/test3/?param1=1¶m=2 .htaccess文件 <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f Rewr
abc.com/article/test1/test2/test3/?param1=1¶m=2
.htaccess文件
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ router.php?q=$1 [NC]
</IfModule>
我得到的输出是article/test1/test2/test3/
但是我需要输出为
article/test1/test2/test3/?param1=1¶m=2
问题是您的重写规则没有保留参数,您需要将[R=302,L]
添加到规则中。将规则行更改为
RewriteRule .* router.php [END]
您要查找的所有信息都在PHP中,
$\u服务器['REQUEST\u URI']
中,您可以根据需要进行解析。例如,为什么您希望这样,而不能通过$\u GET['param1']
获得这些信息?QSA可能对您更有帮助,但谁知道呢。使用QSA
你会得到如下查询字符串:q=article/test1/test2/test3/¶m1=1¶m=2
这就是你要找的吗?QSA
对我有用。我添加了RewriteRule^(.*)$router.php?q=$1[QSA,L]
,我能够获得所有参数。非常感谢你指导我。
RewriteRule .* router.php [END]