rewrite for non-existing subdomains?

Using a single web hosting account to host multiple sites

rewrite for non-existing subdomains?

Postby jimmy » Fri Mar 23, 2007 4:12 am

Hello folks,

I am a newbie in the area of domain management. I have some existing subdomains redirecting to some internet sites (not just to mine), work fine.
The problem is the rest of the non-existing subdomains, calling them I just get a kind of green Apache and Cpanel introduction page from my host company. I want to avoid this intro page, so in case of any non-existing subdomain I would like to have a redirection to (let's say) mydomain.com.
I have Cpanel and Apache, no virtual private server used. The existing subdomains have their own directories and .htaccess files under public_html directory, their rewrite code are similar to this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysubdomain.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mysubdomain.example.com$
RewriteRule ^(.*)$ http://www.targetdomain.com [R=301,L]

All the existing rewrites like the above are fine and working well.

My intension is to try to keep the mechanism above (as well as the different redirections of the existing subdomains) and redirect the non-existing subdomains to one domain only.
According to what I found in a topic viewtopi...5a242e 4f8641 , I tried similar to this code:

RewriteEngine on
RewriteRule ^(.*) http://www.test.com/$1 [P,L]

I placed my attempt into the .htaccess file of the root as well as the .htaccess file of the public_html, not working.
I only get the intro page of the host when calling non-existing subdomains. I think there should be a way to solve this problem, please help me. I tried to create several custom error handling pages, no way (but this area can also have a solution, I don't know).


Do you have any idea?

Thank you in advance,


jimmy
jimmy
 
Posts: 3
Joined: Fri Mar 23, 2007 4:07 am
Location: Hungary

Postby richardk » Fri Mar 23, 2007 2:14 pm

For mod_rewrite to get processed, it has to be in the document root of the (not existing) sub domains, so wherever the green page cpannel is (if it is a real file/directory). If it doesn't exist or you don't have access to it you will need to ask your hosting company.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jimmy » Sat Mar 24, 2007 8:47 am

richardk wrote:For mod_rewrite to get processed, it has to be in the document root of the (not existing) sub domains, so wherever the green page cpannel is (if it is a real file/directory). If it doesn't exist or you don't have access to it you will need to ask your hosting company.


1.
"For mod_rewrite to get processed, it has to be in the document root of the (not existing) sub domains"

- Indeed, I assumed the same. For the existing subdomains (what I defined in Cpanel using subdomains redirection), for example gadgets.example.com should create the directory structure root/public_html/gadgets (and its .htaccess file under gadgets). So I guess, mod_rewrite works in this manner using .htaccess file from gadgets. This is very fine. The problem occures when I try to redirect a non-existing subdomain using a .htaccess file from root or root/public_html directory, not working, only green Cpanel intro page I get.

2.
" so wherever the green page cpannel is (if it is a real file/directory). If it doesn't exist or you don't have access to it you will need to ask your hosting company."

- I couldn't find the green Cpanel page in my filesystem, I am quite sure that I cannot access it. The support from my host company said that it would be possible to modify the green Cpanel page to my needs, but this is a possibility we both agree not the way to do (because other users would see the modified Cpanel page tailored to my page). My host company suggested me a virtual private server for the future, so I think in this case I can really edit my green Cpanel page. However, I hoped that there would be a much more simple solution with my existing "configuration".
jimmy
 
Posts: 3
Joined: Fri Mar 23, 2007 4:07 am
Location: Hungary

Postby richardk » Sun Mar 25, 2007 10:40 am

If they could send all your sub domain requests (existing and not existing) to one directory (eg. public_html/subdomains), you could do all the redirects in one .htaccess file and have a catch all redirect at the end. But you can't use mod_rewrite if the requests go to the cpannel page.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Redirect for subA
RewriteCond %{HTTP_HOST} ^(www\.)?subA\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.tragetA.com/$1 [R=301,L]

# Redirect for subB
RewriteCond %{HTTP_HOST} ^(www\.)?subB\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.tragetB.com/$1 [R=301,L]

# Catch everything else
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule .* http://www.domain.com/? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jimmy » Mon Mar 26, 2007 12:52 pm

richardk wrote:If they could send all your sub domain requests (existing and not existing) to one directory (eg. public_html/subdomains), you could do all the redirects in one .htaccess file and have a catch all redirect at the end. But you can't use mod_rewrite if the requests go to the cpannel page.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Redirect for subA
RewriteCond %{HTTP_HOST} ^(www\.)?subA\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.tragetA.com/$1 [R=301,L]

# Redirect for subB
RewriteCond %{HTTP_HOST} ^(www\.)?subB\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.tragetB.com/$1 [R=301,L]

# Catch everything else
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule .* http://www.domain.com/? [R=301,L]




I tried to adapt the example above, I got the cpanel page. So it seems that mod_rewrite cannot be used. Anyway, thank you very much for your help.



All the best,

jimmy
jimmy
 
Posts: 3
Joined: Fri Mar 23, 2007 4:07 am
Location: Hungary


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 17 guests

cron