How to redirect to external URLs UTF-8 encodding?

Discuss practical ways rearrange URLs using mod_rewrite.

How to redirect to external URLs UTF-8 encodding?

Postby jparra » Wed Mar 25, 2009 4:11 am

Hi there,

I got the next trouble, i have to redirect from my domain to external URLs that come inside the QUERY_STRING, but some times a recives those URLs on UTF-8 encoding (I really need to recive it like this).

Examples:
mydomain.com/index?page=http%3a%2f%2fwww.google.com --> must redirect to http://www.google.com
localhost/home.htm?page=http%3a%2f%2ftakeforum.com%2fdatakeydev --> must redirect to http://takeforum.com/datakeydev

I'm trying with this code, but no luck yet. The 301page chage the link to http://127.0.0.1/?page=http://google.com.

Code: Select all
rewriteEngine on
RewriteMap escaping int:escape

RewriteCond %{QUERY_STRING} ^.*_page=(http.*)$ [OR]
RewriteCond %{QUERY_STRING} ^.*_page=(www\..*)$
RewriteRule ^/.*$ ${scaping:%1} [R,L]


And my rewrite log show:
Code: Select all
init rewrite engine with requested uri /inicio.jsp
applying pattern '^/.*$' to uri '/inicio.jsp'
RewriteCond: input='page=www.google.com' pattern='^.*page=(http.*)$' => not-matched
RewriteCond: input='page=www.google.com' pattern='^.*page=(www\..*)$' => matched
rewrite '/inicio.jsp' -> ']?'
split uri=]? -> uri=], args=<none>
explicitly forcing redirect with http://127.0.0.1:8080/]
escaping http://127.0.0.1:8080/] for redirect
redirect to http://127.0.0.1:8080/%5d [REDIRECT/302]


Any help?????? :-?
jparra
 
Posts: 2
Joined: Wed Mar 25, 2009 3:18 am
Location: España

Postby richardk » Wed Mar 25, 2009 3:27 pm

Code: Select all
${scaping:%1}

should be
Code: Select all
${escaping:%1}


You should not be matching an underscore before page=.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteMap escaping int:escape

RewriteCond %{QUERY_STRING} ^()(.*&)?page=(http.+)$ [NC,OR]
RewriteCond http://%{QUERY_STRING} ^(http://)(.*&)?page=(www\..+)$ [NC]
RewriteRule ^/.*$ ${escaping:%1%3} [R,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jparra » Thu Mar 26, 2009 1:48 am

Thanks richard,

I haven't seem that stupid error:
Code: Select all
${scaping:%1} should be ${escaping:%1}

But i solved the issue by changing the RewriteMap directive:
Code: Select all
From:
RewriteMap escaping int:escape
To:
RewriteMap escaping int:unescape


Now i can put a smile on my face... jejeje :D :D :D :D
jparra
 
Posts: 2
Joined: Wed Mar 25, 2009 3:18 am
Location: España


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 17 guests

cron