重写查询字符串参数到URL阿帕奇重写、字符串、阿帕奇、参数

由网友(遗忘不想遗忘的遗忘)分享简介:网址进入Apache的:URL coming into Apache: localhost:8888/game?level=0这应该出来的Apache网址:URL that should be coming out of apache: localhost:8888/level...

网址进入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)

阅读全文

相关推荐

最新文章