.htaccess 如何编写这个特定的mod_rewrite指令?

.htaccess 如何编写这个特定的mod_rewrite指令?,.htaccess,.htaccess,您好,我是mod_rewrite新手,需要重写以下uri: testsite/payBill?token=EC-8TM276595T982014G&payrid=V3GMCKGHW5XXU 像这样的事情 testsite/index.php?PayBill和token=$1和PayerID=$2 我一直在搜索,包括从这个网站的一些例子,但没有成功地找到类似我的情况 …修订版 更具体地说:这是我的基地:重写基地/tshirtshop。 这是我需要重写的URL https://localhost/t

您好,我是mod_rewrite新手,需要重写以下uri:
testsite/payBill?token=EC-8TM276595T982014G&payrid=V3GMCKGHW5XXU
像这样的事情
testsite/index.php?PayBill和token=$1和PayerID=$2

我一直在搜索,包括从这个网站的一些例子,但没有成功地找到类似我的情况

…修订版
更具体地说:
这是我的基地:重写基地/tshirtshop
这是我需要重写的URL

https://localhost/tshirtshop/payBill?token=EC-2FT032799N454992F&PayerID=V3GMCKGHW5XU

例如:
https://localhost/tshirtshop/index.php?PayBill&token=$1&PayerID=$2

这应该可以

RewriteEngine On

# Either RewriteBase has to point to the base or the RewriteRule has to be ^(.*)$ /index.php/$1 [L] not ^(.*)$ index.php/$1 [L]
RewriteBase /testsite/

# Only do this when the file doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f

# Only do this when the directory  doesn't exist
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?(.*)$ /index.php?$1&$2 [L]

Mod rewrite用于将一个URL转换为另一个URL或将一个URL的内容反映到另一个URL。如果结果URL的数据不包含在原始URL中,那么我认为这是不可能的


也许您想用PHP实现这一点,我建议您将所有URL重写到主PHP文件中,然后从那里控制所有导航流。

尝试将以下内容添加到.htaccess文件中

RewriteEngine On
RewriteBase /tshirtshop/

RewriteCond %{HTTPS} on 
RewriteCond %{REQUEST_URI} ^/tshirtshop/paybill  [NC]
RewriteCond %{QUERY_STRING} ^token=(.+)&payerid=(.+)  [NC]
RewriteRule .* index.php?PayBill&token=%1&PayerID=%2 [L]

testsite/index.php中的
PayBill
是必需的吗?PayBill&token=$1&PayerID=$2
还是打字错误?PayBill是必需的,也是非常必要的。到目前为止,所有建议都不起作用。我编辑后加入了https和tshirtshop。如果它不起作用,您能否提供更多详细信息,例如,您正在使用的测试url和您得到的结果,以及它与预期结果的差异。Thank.htaccess位于tshirtshop目录中。ok-编辑以反映这一点。htaccess位于tshirtshop目录中。它工作起来很有魅力!谢谢!