Forum Moderators: phranque

Message Too Old, No Replies

404 error in a particular automatic subdomain system

         

Teschio

12:58 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



Hi to all, I have this code in my httpd.conf where:
if i digit www.everything.domain2.com (also without the www prefix) i'm redirected to internal domain1 path of www.domain1.com/everything....
Id like to do this redirect only if "everything" folder exist under www.domain1.com... if it does not exist i'd like to receive a custumed 404 error page...
I tried adding "ErrorDocument 404 /error.php" on my code but it doesn't work (for it no subdir exists)!
How can I do?
This is the code I have:

<VirtualHost www.domain2.com>
ServerName www.domain2.com
ServerAlias domain2.com *.domain2.com
DocumentRoot /home/web/www.domain1.com/website
ErrorDocument 404 /error.php
RewriteEngine on
#my fixed subdomain
RewriteCond %{HTTP_HOST} ^(www\.)?forum\.domain2\.com
RewriteRule (.*) [forum.domain1.com$1...] [R=301,L]
#Redirect 4 domain2.com
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com
RewriteRule (.*) [domain1.com$1...] [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain2\.com
RewriteRule (.*) /%2$1 [L]
</VirtualHost>

Thank you.

jdMorgan

2:48 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to use RewriteCond to test for "directory exists." I'll get you started with an example that might work, but you're probably going to have to adapt this to your particular server and needs, and then test it.

RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain2\.com
RewriteCond %{DOCUMENT_ROOT}/%2 -d
RewriteRule (.*) /%2$1 [L]

Jim

Teschio

4:20 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



It worked!
thanks a lot!

Teschio

4:44 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



Excuse me... now i have:

<VirtualHost www.domain2.com>
ServerName www.domain2.com
ServerAlias domain2.com *.domain2.com
DocumentRoot /home/web/www.domain1.com/website
ErrorDocument 404 /error.php
RewriteEngine on
#my fixed subdomain
RewriteCond %{HTTP_HOST} ^(www\.)?forum\.domain2\.com
RewriteRule (.*) [forum.domain1.com$1...] [R=301,L]
#Redirect 4 domain2.com
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com
RewriteRule (.*) [domain1.com$1...] [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain2\.com
RewriteCond %{DOCUMENT_ROOT}/%2 -d
RewriteRule (.*) /%2$1 [L]
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule (.*) /error.php [L]
</VirtualHost>

and it works... if www.blah.domain2.com does not exist i have the error page...
But I'd like also that if i digit www.existent_subdomain.domain2.com/non_existent_file_or_directory i get an error page... also error2.php is good...

Which modification do i have to make?
Thanks

Teschio

11:13 am on Mar 3, 2005 (gmt 0)

10+ Year Member



Please excuse me again...
I think after your explanation it was easy for me to make the code... but now i'm sure it's a "mission impossible" for my brain!
There are 3 error pages i have to manage...

1)I digit www.non_existent_subdomain.domain2.com ---> will get error_1.php
1a)I digit www.non_existent_subdomain.domain2.com/non_existent_dir_or_file ---> will get error_1.php

2)I digit www.existent_subdomain.domain2.com/non_existent_dir_or_file ---> will get error_2.php

3)I digit www.domain1.com/non_existent_dir_or_file ---> will get error_3.php

The complete code i have in my httpd.conf is this:

<VirtualHost www.domain1.com>
ServerName www.domain1.com
ServerAlias domain1.com *.domain1.com
DocumentRoot /home/web/www.domain1.com/website
RewriteEngine on
#my fixed subdomain
RewriteCond %{HTTP_HOST} ^forum\.domain1\.com
RewriteRule (.*) /home/web/www.domain1.com/website/forum/$1 [L]
RewriteCond %{HTTP_HOST} ^www\.forum\.domain1\.com
RewriteRule (.*) [forum.domain1.com$1...] [R=301,L]
#Redirect 4 domain1.com
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^(www¦forum)\.domain1\.com
RewriteRule (.*) [domain1.com$1...] [R=301,L]
</VirtualHost>

<VirtualHost www.domain2.com>
ServerName www.domain2.com
ServerAlias domain2.com *.domain2.com
DocumentRoot /home/web/www.domain1.com/website
RewriteEngine on
#my fixed subdomain
RewriteCond %{HTTP_HOST} ^(www\.)?forum\.domain2\.com
RewriteRule (.*) [forum.domain1.com$1...] [R=301,L]
#Redirect 4 domain2.com
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com
RewriteRule (.*) [domain1.com$1...] [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain2\.com
RewriteCond %{DOCUMENT_ROOT}/%2 -d
RewriteRule (.*) /%2$1 [L]
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule (.*) /error_1.php [L]
</VirtualHost>

Really Thanks!

Teschio

6:02 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



No idea?

Teschio

4:37 pm on Mar 4, 2005 (gmt 0)

10+ Year Member



up..