繁体   English   中英

mod_rewrite GET表单以清理URL

[英]mod_rewrite GET form to clean URL

我曾尝试搜索,但只想出了这个链接 ,我可以使用它,只是不能正确地应用于我当前的情况。

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]

截至目前,它将重定向

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

http://localhost/highscores/personal/test

喜欢它应该。

但是我有一个比较功能,它可以提交GET请求,例如:

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

需要像这样出来

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

但它出来像

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

编辑:使用此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]

您需要修改规则

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

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

因为贪婪的正则表达式。 如果找到/则需要中断(.*)部分

暂无
暂无

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

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