Forum Moderators: phranque

Message Too Old, No Replies

Back button does not work when the redirect results in a 404

         

engenius

9:29 pm on Oct 28, 2009 (gmt 0)

10+ Year Member



My goal is to take all urls of the form "/eov/someagency/some/dir/somefile.php" and redirect them internally to "/some/dir/somefile.php?agency=someagency". I then use the agency field to show appropriate co-branding images, etc.

The file I have now works perfectly except when "some/dir" or "somefile.php" does not exist. I get the expected 404 page but then I can not use the back button to go back to the previous page. I just keep getting the 404 page.

There is also an issue when the trailing '/' is left off for directories. Navigating to "/eov/someagency/some/dir" ends up externally redirecting the user to "/some/dir/?agency=test" instead of internally.

My htaccess file is shown below:

==

Options +FollowSymlinks All -Indexes

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^example. com $
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule (.*)index.php$ http://www.example.com/$1 [R=301,L]

RewriteRule ^eov/(.+?)/(.+)?$ $2?agency=$1 [QSA,L]

==

The first two sections are just to force www and to hide index.php from the url.

Thank you for any help.

g1smd

2:30 am on Oct 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Index rule should be before the www rule to avoid a double redirect for index with www.

The .* pattern in the index redirect is very inefficient. Check old posts in this forum for a much more efficient version.

RewriteBase /
is the default, so does not need to be stated.

The period in each of the patterns needs to be escaped.

Let's get all of those fixed before moving on to the other questions...

jdMorgan

3:12 am on Oct 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This pattern appears to be broken, specifically the bolded part:
 ^eov/[b](.+?)[/b]/(.+)?$ 

I have no idea what mod_rewrite or the regex matching engine will do when it finds a "?" quantifer directly following a "+" quantifier, but it's probably not what you wanted...

You can omit the "+FollowSymLinks" from your options, since that is redundant with "All".

There appears to be a spurious space preceding the "$" end-anchor in your first RewriteCond.

Since this code does not know (or care) whether "somedir" or "someagency" exists or not, it is likely a bug in your script. Since *all* URLs of the form /eov/x/y are rewritten to the script, it must be your script that is producing the 404 error page -- and it is very likely doing so incorrectly, by redirecting to it instead of simply 'including' it and sending its contents to the client along with a server status header of "404-Not Found". You can easily check this with a server headers checker tool such as the "Live HTTP Headers" add on for Firefox.

Jim

g1smd

10:18 am on Oct 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In my post, "index with www" should have said "index request without www".