views:

663

answers:

3

Hi friends,

I'm working with PHP. I have an .htaccess file like below, and it redirects to homepage rather than 404 error page :/ what can be the problem here? Appreciate helps! thanks a lot!

ErrorDocument 404 /new/err404.html
RewriteEngine On
RewriteBase /new/

RewriteRule ^login.html$ index.php?s=login&a=loginDo [QSA,L]
RewriteRule ^logout.html$ index.php?s=login&a=logoutDo [QSA,L]
RewriteRule ^([^/]*).html$ index.php?s=$1 [QSA,L]
RewriteRule ^members/([^/]*)$ index.php?s=profile&username=$1 [QSA,L]
RewriteRule ^([^/]*)/$ index.php?s=listing&search[cityString]=$1 [QSA,L]
RewriteRule ^([^/]*)/([^/]*)/$ index.php?s=listing&search[neighborhoodString]=$2 [QSA,L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*).html$ index.php?s=details&seo_friendly=$3 [QSA,L]
+3  A: 

The URL path or your error document /new/err404.html without the path prefix /new/ is just err404.html. And that will be matched by your third rule.

You could extend that rule and exclude such the error documents:

RewriteCond $1 !^err[45][0-9][0-9]$
RewriteRule ^([^/]*)\.html$ index.php?s=$1 [QSA,L]
Gumbo
Thanks so much Gumbo. I just changed the /new/err404.html to err404.html . now it doesnt redirect to homepage, but it is not redirecting to 404 page as well. it just writes "err404.html" at the content and url stays as it was mistaken :/
artmania
@artmania: You shouldn’t redirect on errors. Responding with a 404 status code has a different meaning than redirecting.
Gumbo
I just edited to ErrorDocument 404 http://www.blabla.com/new/err404.html and working fine. but as I have read at forums, it is not good to give redirections with domain...
artmania
I second that you shouldn't redirect on 404s. Pages that don't exist *shouldn't try to pretend they exist*! If nothing else, it's not helpful to SEO and Google advises against it.
Gabriel Hurley
I appreciate your kind help! I'm sorry I didn't understand what exactly you mean :/ if page doesnt exist, it just redirecting to err404.html . or do you mean anything about the rest of .htaccess codes?
artmania
@artmania: If the server cannot find the requested document, it will send the 404 status code and serve the document specified for an 404 error, in your case the document `/new/err404.html`. That’s the appropriate behavior. If you now want to redirect to something different (and that happens if you specify an absolute URL in `ErrorDocument`), the server will use a 302 status code rather than the appropriate 404 status code. And a 302 means “the requested resource *does* exist but use the following location to retrieve it”.
Gumbo
A: 

Why are you trying to use rewrite rules for your 404 error? Why not just use:

 ErrorDocument 404 /new/err404.html

like you have on the first line? Are you wanting the 404 to stay relative to the directory that the user is trying to go to?

Anthony
A: 

I think a more important question, is why you are redirecting 404's to your home page?

The user needs to know that the page is dead/bad, and so does Google. And you need to investigate where the 404's are coming from.

Redirecting your 404's to your home page will tell Google that your links are A-ok, and you may hurt your rankings depending on how many links are being redirected, as Google may see it as duplicate content.

Say you put a rule that affects 5,000 pages - then google comes and sees 5,000 URL's with the same exact content - the home page, how does it know those were supposed to be 404's to begin with?

Fix your 404's. And if you had legitimate content that needs redirecting, well, redirect them to their new page, or the closest semantic page available.

jim