Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Not your Usual 404 Problem

11:13 am on Apr 23, 2013 (gmt 0)

New User

joined:Apr 23, 2013
posts: 1
votes: 0

I have a bit of a problem the code i put in the HTACCESS file is not aloowing me to access my admin area (back office) of my website it just redirects me to the homepage. "RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . / [L,R=301]" .
Now it works perfect for the 404's and redirects them permanently. Now if i use "ErrorDocument 404 it catches the 404's but doesn't 301 them only 302's them meaning temporary. Is There some sort of code i can add to the first code so that it excludes example.com/admin9891.

[edited by: Ocean10000 at 1:42 pm (utc) on Apr 23, 2013]
[edit reason] TOS - Removed URL [/edit]

7:08 pm on Apr 23, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
votes: 244

I count at least two different questions. Easy one first:
Now if i use "ErrorDocument 404 it catches the 404's but doesn't 301 them only 302's them meaning temporary.

Crystal ball says your ErrorDocument directive is in this form

ErrorDocument 404 http://www.example.com/404.html

NEVER give the domain name for an ErrorDocument. This converts the error handling into a redirect. It's 302 rather than 301 because that is the default form of a redirect. But this detail is irrelevant because you don't want ANY form of redirect. A 404 is a 404:

ErrorDocument 404 /404.html

That's all. Leading slash = root. If your error documents are collected elsewhere for convenience, it might be something like

ErrorDocument 404 /errordocs/404.html

Now then...
RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . / [L,R=301]

Can I assume the Forums ate a few line breaks so it's really

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]

"If user-agent requests any file whatsoever that doesn't exist, redirect to the root."

Smells like your vanilla CMS RewriteRule... except what's the R=301 doing there? The whole point of this type of rewrite is to let the user think they're at

while really they're getting content from

... with further wtf? at this point, because the RewriteRule doesn't include any provision for remembering what page the user thought they were going to. With a simple rewrite it wouldn't matter because the original URL is still there. Change it to a redirect and you've effectively killed all your pages. So you've got more problems than the one you posted about.

If your admin area involves a named file in an area that physically exists, there's nothing in the quoted rule that would prevent you from getting there. But the quoted rule only checks for -f files not for -d directories. So if you are trying to get to

and all you entered was

the rule will kick in and you'll be redirected. It is probably easiest to code an outright exception in your generic rewrite. Exclude all requests for everything in the admin directory:
RewriteCond %{REQUEST_URI} !/this-way-for-robots/

Just make sure the admin directory is suitably password-protected.

Come to think of it: What happens to ordinary requests after they meet the global redirect? I'd expect an infinite loop.

And then there's the matter of requests for non-page files...
1:53 pm on Apr 27, 2013 (gmt 0)


WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
votes: 8

welcome to WebmasterWorld, webb1985