Forum Moderators: phranque
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.
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...
^eov/[b](.+?)[/b]/(.+)?$ 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