Link to home
Start Free TrialLog in
Avatar of Luís 𝐂𝐥𝐚𝐫𝐚 𝐅𝐞𝐫𝐧𝐚𝐧𝐝𝐞𝐬, MBA
Luís 𝐂𝐥𝐚𝐫𝐚 𝐅𝐞𝐫𝐧𝐚𝐧𝐝𝐞𝐬, MBA

asked on

redirect if 404 (Apache/php)

I want to redirect not found pages to index.php.

how do i send the user to index page if they get a 404 error?

I'm already using some rewrite rules to improve SEO like you could see in joigned file.
htaccess.txt
SOLUTION
Avatar of Kalpan
Kalpan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As far as going Joomla specific, you can look at :

http://forum.joomla.org/viewtopic.php?p=1973770

if you really want only to point to the homepage then in .htaccess just write:

ErrorDocument 404 /index.php
Avatar of Luís 𝐂𝐥𝐚𝐫𝐚 𝐅𝐞𝐫𝐧𝐚𝐧𝐝𝐞𝐬, MBA
Luís 𝐂𝐥𝐚𝐫𝐚 𝐅𝐞𝐫𝐧𝐚𝐧𝐝𝐞𝐬, MBA

ASKER

Hello,
 
Thankyou guys for all your answers.
I tried already to setup ErrorDocument 404 /index.php in my .htaccess file, but nothing happends. My website is hosted at hostgator, do you think I couldn't setup Error pages in htaccess ? In Cpanel I could setup error pages, but it doesn't work to.
Thankyou
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello every body,

Finally I got many answers but nobody answers to my question. Whatever, my case is quite simple:

I have many urls indexed in Google. But I changed the structure of the website and don't care about old pages. But I want to redirect all visitors when a page indexed by Google is not found.

mywebsite.com/index.html exist -> nothing to do
mywebsite.com/anysubdirectory/*.html exist -> nothing to do
mywebsite.com/anysubdirectory/*.html doesn't exist -> redirect to root page

That's all.

Somebody could help me to rewrite the rules in joigned .htaccess file or explain me a good way to do that?

Thankyou
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello,

I had  ErrorDocument 404 /index.php in one of my websites where I'm not using rewrite rules and it works fine.

But where I'm using the rewrite rules that you find in the htaccess.txt joigned to the question, it doesn't work.

Take a look at: http://www.mycarvsyours.com/directory

The path directory doesn't exist and I get an error page and no redirection.

Thank you for your help


Where in the file did you have the ErrorDocument, beginning or end?

I'll have to read and see if I can find what order the statements are processed, but I beleive that you would need it at the end.
Hello,

I tried both, but it doesn't work.

Joomla rewrite rules send error 404 to a page that shows Component not found. I guess that this rewrites rules used by joomla send visitor to this error page, I was thinking that I could change this rule to redirect visitor to index.php.

What do you think?


There's the rewrite rules I'm using and my try  without ErrorDocument:

#Joomla rewrite rules:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php


#My try to redirect visitor in case of error 4 (not working)
#writeCond %{HTTP_HOST} ^mycarvsyours\.com/.*$
#RewriteRule (.*) http://www.mycarvsyours.com/.*$1 [R=404,L]
#RewriteRule ^$ http://www.mycarvsyours.com/index.php [L,R=404]

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello,

That's the best way. But I discovered that Joomla overrides the htaccess file when it comes to 404 errors.

Take a look at: http://forum.joomla.org/viewtopic.php?f=428&t=282063

This is a bad solution that works, but show the 404 error before redirection. Somebody understand how Joomla overrides htaccess?  
Thanks for the points.  Although I saw Joomla, it never hit me until now.  Have you tried reading either of the following.

http://docs.joomla.org/Tutorial:Create_a_Custom_404_Error_Page

http://forum.joomla.org/viewtopic.php?f=199&t=251089
You did it! Thank you so much. I' work on voip (cisco & asterisk), if you have any question about, it will be my pleasure.