htaccess传递1个查询字符串

时间:2014-07-23 11:57:41

标签: php .htaccess mod-rewrite

我的.htaccess路径就像

/home/user1/public_html/subdomain/user/transfer/.htaccess

我在与.htaccess

相同的文件夹上有一个index.php

index.php正试图捕获查询字符串" action"通过重写操作作为最后一个查询,如

subdomain.mydomain.com/user/transfer/action 
对于亚历山大和@Trick来说,行动可以是现金,信贷,贷款或其他话。

1 个答案:

答案 0 :(得分:1)

假设您收到了请求

http://subdomain.mydomain.com/user/transfer/index.php?action=register

并希望将内部视为

http://subdomain.mydomain.com/user/transfer/transferregister

然后你应该放在.htaccess

RewriteEngine On
RewriteBase /user/
RewriteCond %{REQUEST_URI} ^transfer/index\.php$
RewriteCond %{QUERY_STRING} ^action=(.*)$ [NC]
RewriteRule .* transfer/transfer%1? [R=302,L]

如果你想要相反的,那就是你得到了一个请求

http://subdomain.mydomain.com/user/transfer/transferregister

并希望将内部视为

http://subdomain.mydomain.com/user/transfer/index.php?action=register

然后你应该放在.htaccess

RewriteEngine On
RewriteBase /user/
RewriteCond %{REQUEST_URI} ^transfer/transfer
RewriteRule ^transfer/transfer(.*)$ transfer/index.php?action=$1? [R=302,L]