Jump to content
xisto Community
FirefoxRocks

Subdomain Redirection

Recommended Posts

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

For example:
http://forums.xisto.com/no_longer_exists/ goes to http://forums.xisto.com/no_longer_exists/ where I have a folder called feral in my public_html folder.

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

How do I do this within cPanel?

Edited by FirefoxRocks (see edit history)

Share this post


Link to post
Share on other sites

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://forums.xisto.com/no_longer_exists/ should redirect to your /feral/ directory.

Share this post


Link to post
Share on other sites

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://forums.xisto.com/no_longer_exists/ should redirect to your /feral/ directory.


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

Share this post


Link to post
Share on other sites

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

Options -Indexes +FollowSymLinksRewriteEngine OnRewriteBase /RewriteCond %{HTTP_HOST} ^example.com [NC]RewriteRule ^(.*)$ http://example.com [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://terriswallow.com/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. :mellow:

Share this post


Link to post
Share on other sites

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,

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
ThanksSubdomain Redirection

Quatrux, thank you so much for posting this. Exactly what I was looking for and I searched everywhere for this.. :)

-reply by Deran

 

Share this post


Link to post
Share on other sites

You can either use cpanel to forward them, or do what I do, and use a simple .htaccess file

 

Make a text file, name it htaccess - add this info:

 

Redirect 301 / http://forums.xisto.com/no_longer_exists/

 

Then you simply upload via ftp, and use it in whatever directory you need it in. (main file if using Xisto to the site above),

and then rename it with a period in front of the htaccess (.htaccess).

Very easy to do, and works well.

Edited by xamire (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.