开发者

RewriteRule - loop redirection

i need help with this 2 rewrite rules:

RewriteEngine On
RewriteBase /

# folder/script.php?A=1&B=2  ->  xyz/1/2 (REDIRECT)
RewriteCond %{QUERY_STRING} ^A=([^&]+)&B=([^&]+)$
RewriteRule ^folder\/script\.php$ /xyz/%1/%2? [R=301,L]

# xyz/1/2  ->  folder/script.php?A=1&B=2 (REWRITE)
RewriteRule ^xyz\/([^\/]+)\/([^\/]+)$ /folder/script.php?A=$1&B=$2 [L]
  • First I need "REDIRECT"

    FROM: efectorelativo.net/folder/script.php?A=1&B=2

    TO: efectorelativo.net/xyz/1/2

  • Then i need "REWRITE" not "REDIRECT"

    FROM: efectorelativo.net/xyz/开发者_如何学JAVA1/2

    TO: efectorelativo.net/folder/script.php?A=1&B=2

EDIT: (working code, thanks to Gumbo)

RewriteEngine On
RewriteBase /

# folder/script.php?A=1&B=2  ->  xyz/1/2 (REDIRECT)
RewriteCond %{THE_REQUEST} \?A=([^&]+)&B=([^\s&]+)
RewriteRule ^folder\/script\.php$ /xyz/%1/%2? [R=301,L]

# xyz/1/2  ->  folder/script.php?A=1&B=2 (REWRITE)
RewriteRule ^xyz\/([^\/]+)\/([^\/]+)$ /folder/script.php?A=$1&B=$2 [L]


Inspect the request line in THE_REQUEST instead of the current URL:

# folder/script.php?A=1&B=2  ->  xyz/1/2 (REDIRECT)
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?A=([^&]+)&B=([^&\ ]+)\ 
RewriteRule ^folder/script\.php$ /xyz/%1/%2? [R=301,L]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜