重写查询字符串参数到URL阿帕奇 [英] Rewrite query string parameter into URL Apache
问题描述
网址进入Apache的:
URL coming into Apache:
localhost:8888/game?level=0
这应该出来的Apache网址:
URL that should be coming out of apache:
localhost:8888/level0/game
可能有人好心帮我建立这个重写?
Could someone kindly help me to create this rewrite ?
试着用以下解决这个问题:
Tried to solve it with following:
RewriteEngine On
RewriteRule ^game\/+(.*?)\?+level=+([0-9]+) /level$2/$1 [L,QSA]
没有运气,因为它不匹配。
With no luck since it does not match.
谢谢, 彼得·
推荐答案
要能够从查询字符串获取值,则需要一个的RewriteCond%{QUERY_STRING}
指令,以使捕获组将作为%N
以下重写规则占位符:
To be able to capture values from the query string, you need a RewriteCond %{QUERY_STRING}
directive, so that captured group will be available as %n
placeholders in the following RewriteRule:
RewriteCond %{QUERY_STRING} ^level=(.*)$
RewriteRule ^game /level%1/game [L]
如果您键入 /游戏等级= 0
在浏览器中,Apache将打开 / LEVEL0 /游戏
?;无需追加查询字符串的URL重写( QSA
标志)
If you type /game?level=0
in the browser, apache will open /level0/game
; no need to append the query string to the rewritten url (QSA
flag)
这篇关于重写查询字符串参数到URL阿帕奇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!