Nov 8, 2009

Subdomain Redirection

free web hosting
Open Discussion & Free Web Hosting > Astahost > Hosted Members Support

Subdomain Redirection

FirefoxRocks
I would like to know if pages can redirect to the subdomain URL instead of the folder in public_html.

For example:
http://feral.portal.trap17.com/ goes to http://portal.trap17.com/feral/ where I have a folder called feral in my public_html folder.

I want http://portal.trap17.com/feral/ to go to http://feral.portal.trap17.com/ and the pages within the feral directory to do that too. (e.g. http://portal.trap17.com/feral/armyCalc.php to http://feral.portal.trap17.com/armyCalc.php).

How do I do this within cPanel?

Comment/Reply (w/o sign-up)

Nabb
You could try hacking something up using mod_rewrite. For example, you could rewrite http://portal.trap17.com/feral/ to http://portal.trap17.com/redir.php?q=, which would redirect them based on the value in q. Hopefully this doesn't cause an infinite redirection loop..

Comment/Reply (w/o sign-up)

tansqrx
Create a subdomain under your Cpanel

1. Log into your Cpanel.
2. Click Subdomains under the Domains group.
3. Enter “feral” in the Subdomain field
4. Enter “feral/” in the Document Root field.
5. Click Create.

If all goes well and I understand what you want then this should be your solution. http://feral.portal.trap17.com/ should redirect to your /feral/ directory.

Comment/Reply (w/o sign-up)

FirefoxRocks
QUOTE (tansqrx @ Mar 16 2009, 04:26 PM) *
Create a subdomain under your Cpanel

1. Log into your Cpanel.
2. Click Subdomains under the Domains group.
3. Enter "feral" in the Subdomain field
4. Enter "feral/" in the Document Root field.
5. Click Create.

If all goes well and I understand what you want then this should be your solution. http://feral.portal.trap17.com/ should redirect to your /feral/ directory.


Other way around, I want the /feral directory to redirect to the subdomain.

Comment/Reply (w/o sign-up)

Quatrux
You need to use htaccess files in order to do this, one way is to use mod_rewrite, here is the code:

CODE
Options -Indexes +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]

RedirectMatch 301 ^/blog/(.*)$ http://blog.example.com/$1


So whenever someone will go to example.com/blog/ it will redirect him/it to your subdomain blog.example.com with a permanent redirect code 301, which is good for lets say spiders and other web robots.

More about it on this blog entry I found through google: http://blog.ninedays.org/2008/03/11/htacce...-and-force-www/

Another way would be doing the same thing with PHP, if you're using index.php you just need to check $_SERVER superglobal HTTP_HOST as I remember if it's not blog.example.com but only example.com also redirect with a 301 code using header() + Location, it will do the same, but I believe using htaccess method is much better, as I think it will also redirect example.com/blog/images/Logo.jpg to blog.example.com/images/Logo.jpg where using PHP would only redirect dynamic pages. smile.gif

 

 

 


Comment/Reply (w/o sign-up)

TavoxPeru
Excelent information Quatrux, some time ago i had try to do something similar with bad results, i never can made it to work. When i have some spare time i will try again, i hope now it works.

Best regards,

Comment/Reply (w/o sign-up)

FirefoxRocks
Do I put this htaccess file within the /feral/ directory or the / root directory? And I would prefer to redirect all resources, not just the PHP pages.

Comment/Reply (w/o sign-up)

Quatrux
I guess it's enough to put the .htaccess file in you root directory of subdomain.example.com so whenever someone goes to any resource in example.com/subdomain/ he will get redirected to the same resource through the subdomain.example.com

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Subdomain Redirection

  1. How To Host An External Subdomain? - (2)
  2. Not Able To See My Subdomain Page - I registered, it comes up page not found (7)
    Would an admin be so kind as to please tell me why I had to register again on my account that
    I had previously made, but it's still not coming up. I type in the URL and it comes up "Page
    Not Found" or "Action Cancelled." I'm not able to reach my Cpanel either. The URL is
    http://tobias.astahost.com . Any help would be greatly appreciated. Tobias ...



Looking for Subdomain, Redirection

See Also,

*SIMILAR VIDEOS*
Searching Video's for Subdomain, Redirection
advertisement



Subdomain Redirection

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com