简体   繁体   English

通过.htaccess将URL参数传递给php文件

[英]Pass URL parameter to php file through .htaccess

I need to pass URL along with all parameters through .htaccess to get in other php file. 我需要通过.htaccess传递URL以及所有参数,以获取其他php文件。 For example: 例如:

URL : abc.com/article/test1/test2/test3/?param1=1&param=2 网址: abc.com/article/test1/test2/test3/?param1=1&param=2

.htaccess file .htaccess文件

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ router.php?q=$1 [NC]

  </IfModule>

router.php router.php

echo $_GET['q'];

I am getting output as article/test1/test2/test3/ 我得到的输出为article/test1/test2/test3/

But i need output as article/test1/test2/test3/?param1=1&param=2 但是我需要输出为article/test1/test2/test3/?param1=1&param=2

Change the rule line to 将规则行更改为

RewriteRule .* router.php [END]

All the info you're looking for is right there, in PHP, in $_SERVER['REQUEST_URI'] which you can parse however you want. 您要查找的所有信息都在PHP中的$_SERVER['REQUEST_URI'] ,您可以根据需要进行解析。

问题是您的重写规则未保留参数,您需要在规则中添加[R=302,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM