简体   繁体   English

mod_rewrite GET表单以清理URL

[英]mod_rewrite GET form to clean URL

I have tried searching but only came up with this link which I can get to work, just not correctly to apply to my current situation. 我曾尝试搜索,但只想出了这个链接 ,我可以使用它,只是不能正确地应用于我当前的情况。

RewriteCond %{REQUEST_URI} ^/highscores/personal/$
RewriteCond %{QUERY_STRING} ^user1=(.*)$
RewriteRule ^(.*)$ /highscores/personal/%1? [R=301,L,QSA]

RewriteRule ^highscores/personal/(.*)/vs/(.*) personal.php?user1=$1&user2=$2 [L,QSA]
RewriteRule ^highscores/personal/(.*) personal.php?user1=$1 [L,QSA]
RewriteRule ^highscores/skill/(.*) highscores.php?skill=$1 [L,QSA]
RewriteRule ^highscores/(.*) highscores.php?$1 [L,QSA]

As of right now, it will redirect 截至目前,它将重定向

http://localhost/highscores/personal/?user1=test

to

http://localhost/highscores/personal/test

like it should. 喜欢它应该。

But I have a compare function which submits a GET request like: 但是我有一个比较功能,它可以提交GET请求,例如:

http://localhost/highscores/personal/?user1=test&user2=test2

which needs to come out like 需要像这样出来

http://localhost/highscores/personal/test/vs/test2

but it comes out like 但它出来像

http://localhost/highscores/personal/test&user2=test2

Edit: Resolved using help from this htaccess tester 编辑:使用此htaccess测试仪的帮助解决

RewriteCond %{REQUEST_URI} ^/highscores/personal/$
RewriteCond %{QUERY_STRING} ^user1=([^&]+)&user2=(.*)$
RewriteRule ^(.*)$ /highscores/personal/%1/vs/%2? [R=301,L]
RewriteCond %{REQUEST_URI} ^/highscores/personal/$
RewriteCond %{QUERY_STRING} ^user1=(.*)$
RewriteRule ^(.*)$ /highscores/personal/%1 [R=301,L]

You need to edit your rule 您需要修改规则

RewriteRule ^highscores/personal/(.*)/vs/(.*) personal.php?user1=$1&user2=$2 [L,QSA]

to

RewriteRule ^highscores/personal/([^/]+)/vs/(.*) personal.php?user1=$1&user2=$2 [L,QSA]

because of greedy regex. 因为贪婪的正则表达式。 You need to break (.*) section if / is found 如果找到/则需要中断(.*)部分

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

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