开发者

URL rewriting variable name

I am trying to rewrite an URL so that a passed variable is开发者_开发问答 replaced with a new id, for example;

wwww.domain.com/default.php?s=1&lang=en

To be rewritten to:

www.domain.com/default.php?id=1$lang=en

The s variable being replaced with id

I have tried:

RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteCond %{QUERY_STRING} ^s=(.+)$
RewriteRule ^s=(.+)$ id=$1 [R,NC,L]

also

RewriteRule ^s=(.+)$ id=%1 [R,NC,L]

no luck... what am I doing wrong?

Thanks for any help!!


This should work if even if you don't have s as the first variable. (Not sure what you really want.)

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*&)*s=(.*)(&*)$
RewriteRule ^default.php$ default.php?%1&id=%2%3


Try this out:

RewriteRule ^default.php?s=([0-9]+)&lang=en$ default.php?id=$1&lang=en

Edit. A more generic version.

RewriteRule ([^?]+)?s=([0-9]+)&lang=([A-z]{2})$ $1?id=$2&lang=$3
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜