Welcome to WebmasterWorld Guest from 54.81.220.239

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

mod rewrite fails with %2f character

     
8:00 am on Mar 12, 2007 (gmt 0)

New User

10+ Year Member

joined:Mar 12, 2007
posts:26
votes: 0


I'm experiencing some weird problems with this rule:

RewriteRule ^index2.php index.php [R]

Obviously, it's supposed to redirect all requests beginning with index2.php to index.php. The rule works fine if the request is '../index2.php.foo' or
'../index2.php/f/o/o//' but as soon as there is an '%2f' (urlencode('/')) in the request, it will produce a 404 Not Found error. I've seen this behaviour with both Apache/2.2.3 and 1.3.33.

Have I stumbled upon a bug in Apache or am I just overlooking something?

4:12 pm on Mar 12, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Try using the [NE] flag, which overrides the normal URL-encoding. Also, your syntax needs some tweaking:

RewriteRule ^index2\.php$ http://www.example.com/index.php [NE,R=302,L]

You should consider whether you want a 302-Found or 301-Moved Permanently redirect, as dictated by the response you want from search engines. In the absence if the "=30x" specification on the rule's [R] flag, a 302 is the default. This tells search engines to continue to list the old URL, but with the new page content, whereas a 301 tells them to replace the old URL with the new URL in their search results listings.

Jim

7:54 pm on Mar 13, 2007 (gmt 0)

New User

10+ Year Member

joined:Mar 12, 2007
posts:26
votes: 0


Thanks for the help, but I'm still seeing the same problems. It looks like the htaccess file isn't processed at all as soon as there's an %2f in the request.
8:23 pm on Mar 13, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Please post a specific and complete example of the url-encoded URL, changing only the domain name to "example.com" to comply with our TOS. Also, if there is anything generalized or incomplete about the rule posted above, let's see the details on that, too. -- Thanks,

Jim

8:52 pm on Mar 13, 2007 (gmt 0)

New User

10+ Year Member

joined:Mar 12, 2007
posts:26
votes: 0


Here's a simple example - the htaccess file only contains the line ``ErrorDocument 404 "error".

http://example.com/x/thisFileDoesNotExist returns "error" and the error is logged in the error.log.

http://example.com/x/thisFileDoesNotExist%2f returns "Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

[...]", i.e. the default 404 page, and the error is not logged.

This looks more and more like a bug to me.

[edited by: MrManager at 8:53 pm (utc) on Mar. 13, 2007]

11:43 pm on Mar 13, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Ah, OK, it's not a bug, but rather a result of the invalid URL. The naked "%2f" is allowed in a query string. but not in a URL. In order to be valid, it would have to be encoded as %252f, which I think you will find to work as you expect.

Because the URL is itself invalid, the server is rejecting it before any Apache modules are invoked. On my server, not even the custom 404 error page is applied -- The server simply rejects the request out-of-hand.

For more information, see RFC2396 - Uniform Resource Identifiers (URI): Generic Syntax [faqs.org].

Jim

[edited by: jdMorgan at 11:46 pm (utc) on Mar. 13, 2007]