Problem dealing with an encoded URL

Oh, the strange things mod_rewrite does!

Problem dealing with an encoded URL

Postby vinay.chilakamarri » Wed Jul 09, 2008 1:02 pm

Hi,

I am struck with encoded URL's and am not sure how to proceed. I used to match patterns like 'welcome/to/this/page' which worked very well with mod rewrite. But I came across a situation where I get encoded URL's from an application. For example,

https://127.0.0.1:403/welcome/to/this/page is sent as

https://127.0.0.1:403%2Fwelcome%2Fto%2fthis%2fpage

I tried matching the "%2F" to no avail. How do we deal with these kind of issues?
vinay.chilakamarri
 
Posts: 10
Joined: Fri Jun 20, 2008 4:42 pm

Postby richardk » Wed Jul 09, 2008 1:35 pm

Do you get a 404 error when you go to the encoded URL?

You can try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{THE_REQUEST} \ %2f([^\ \?]*)(\?.*)?\  [NC]
RewriteRule !^/ /%1 [QSA]

RewriteRule ^(/.+)%2f(.*)$ $1/$2 [NC,QSA]


You should certainly fix the application.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby vinay.chilakamarri » Thu Jul 10, 2008 11:47 am

Hi Richard,

I do get a 404 not found error when I supply the URL in encoded format.
I too felt that encoding a URL is not needed but they built their application in such a way that if encoded URL is not being sent, rest of their API's dont' work properly. That was very weird to me.

I could understand what Line 1 and line 3 are doing in this rewrite. But I am not sure what Line 2 is doing. Could you please explain the purpose of line 2

RewriteCond %{THE_REQUEST} \ %2f([^\ \?]*)(\?.*)?\ [NC]
RewriteRule !^/ /%1 [QSA]
RewriteRule ^(/.+)%2f(.*)$ $1/$2 [NC,QSA]

Thanks for the help.
vinay.chilakamarri
 
Posts: 10
Joined: Fri Jun 20, 2008 4:42 pm

Postby richardk » Sun Jul 13, 2008 10:09 am

Where are you going to be using this mod_rewrite? (.htaccess file, <VirtualHost, <Directory> or main server configuration)?

I could understand what Line 1 and line 3 are doing in this rewrite. But I am not sure what Line 2 is doing. Could you please explain the purpose of line 2

It is for the first %2f only. It matches only URLs that don't start with a / (!^/) and should replace the first %2f with a / (/%1, %1 from the RewriteCond).

Did it work at all? Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /([^\ \?]*)([^\ \?]*)%2f(\?.*)?\  [NC]
RewriteRule !^/ /%1/%2 [QSA]

RewriteRule ^(/.+)%2f(.*)$ $1/$2 [NC,QSA]

It might need to use a variable instead of just a RewriteRule, though.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby vinay.chilakamarri » Mon Jul 14, 2008 12:03 pm

I use those rules in .htaccess file. The previous solution worked well with what I was targeting for. I may have to deal with couple of more URL's like these in the future. The current solution should help me write rules for the rest. Thanks a lot again for timely help.
vinay.chilakamarri
 
Posts: 10
Joined: Fri Jun 20, 2008 4:42 pm


Return to Idiosyncrasies

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron