PDA

View Full Version : .htaccess error pages


gfxhelp.com
09-18-2008, 03:59 AM
I want to make it so if someone types in a bad url it takes them back to my homepage. Currently the problem I'm having is if someone goes to:
http://www.gfx-help.com/blah123.html
or
http://www.gfx-help.com/blah123
it loads the error page which has the same code as the index.php. I would rather have it redirect back to index.php, but this still works. The problem is if someone goes to:

http://www.gfx-help.com/blah123/blah456/ all of the images and links don't work since most of them are not hard linked.

Does anyone have any idea how to do this? I basically just want any non-existent page to redirect back to my home page. I was thinking of just putting a meta redirect in each of the error pages, but perhaps there's a better way to do this?


My .htaccess currently looks like this...ErrorDocument 400 /400.php
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
ErrorDocument 404 /500.php

RewriteEngine on

RewriteCond %{HTTP_HOST} ^gfx-help.com$
RewriteRule ^/?$ "http\:\/\/www\.GFX\-Help\.com" [R=301,L]

RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]

RewriteCond %{HTTP_HOST} ^gfx-help.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.gfx-help.com$
RewriteRule ^index.php$ "http\:\/\/www\.gfx\-help\.com\/" [R=301,L]


Options All -Indexes

Dismounted
09-18-2008, 04:33 AM
ErrorDocument 400 /index.php
ErrorDocument 401 /index.php
ErrorDocument 403 /index.php
ErrorDocument 404 /index.php
ErrorDocument 404 /index.php
A page explaining the error, then redirecting would be nice.

gfxhelp.com
09-18-2008, 05:00 AM
It works correctly now, but the issue is the paths for images/css are wrong if you go to a page like http://www.gfx-help.com/test1/test2/

I had a replacement variable for image paths which pointed to "images/theme", I changed that to "http://www.gfx-help.com/images/theme" and thought that would fix it, but it didn't help. Perhaps it's happening due to the css paths being incorrect?

Dismounted
09-18-2008, 05:20 AM
Add a base element to the top of your headinclude template:
<base href="http://www.gfx-help.com/" />

gfxhelp.com
09-18-2008, 05:30 AM
Nice, works perfect.

Thanks Dismounted