.htaccess redirect

Status
Not open for further replies.

batori

Active Member
311
2009
26
10
Hi,

Anyone willing to help on a thing or two...

I would like to redirect ALL 404 error pages from a domain to a subdomain.

So like:
Code:
www.page.com/post2857html

On error would go on to :

sub.page.com/post2857.html


Cheers!
 
6 comments
Try this:

ErrorDocument 404 /

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^([a-z0-9\-]+)\.domain\.com$ [NC]
RewriteCond %1 !^www$ [NC]
RewriteRule (.*) http://domain.com/%1 [R=301,L,NC]

put that in your .htaccess on your root folder. This will redirect sub.domain.com => domain.com/sub
 
Thanks for the help and quick reply.

I've tried it and it does not seem to work :(

I need to redirect 404 error when they occur : MYDOMAIN.COM/mypost.html to TEST.MYDOMAIN.COM/mypost.html
 
You can also add your own 404.shtml file to redirect a page not found. Usually the cpanel has an icon to do that. Or do it manually.


for the .htaccess try this:
Code:
ErrorDocument 404 /

 RewriteEngine On 
 RewriteBase / 
 RewriteCond %{HTTP_HOST} ^([a-z0-9\-]+)\.domain\.com$ [NC]
 RewriteCond %1 !^www$ [NC]
 RewriteRule (.*) http://test.domain.com/%1 [R=301,L,NC]
 
Status
Not open for further replies.
Back
Top