views:

16

answers:

1

Hello, 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/1/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]
A: 

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]
Gumbo
Thank you, with a little fix now is working.
Luistar15