Forum Moderators: phranque

Message Too Old, No Replies

How to redirect one subdomain to another?

Need instruction to permanently redirect one subdomain to a new one

         

jadefalcon1

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

10+ Year Member



I'm running apache2 on Server 2003. Everything is working fine. However, I recently decided to move all my content on my pics.mydomain.com into a consolodated media.mydomain.com. I now want to permanently redirect all requests from the pics subdomain to the media subdomain. I want to preserve whatever specific resource request they're asking for (like /gallery/whatever.php).

It'd also be nice if the redirect directive could be used, so that the permanently moved (http 30....2?) code can be shown. I want them to see the new url, instead of being shown the old one, even though they're browsing the new one.

I've got extremely rudimentary understanding of Apache, so please speak slowly, using small words :)

jdMorgan

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

WebmasterWorld Senior Member 10+ Year Member



jadefalcon1,

Welcome to WebmasterWorld!

The documentation cited in our charter [webmasterworld.com] is a good place to start. You'll need to use mod_rewrite to do this redirect, and it's not a good idea to try to use mod_rewrite before understanding it; You can easily create code that will cripple your site, either by stopping it from serving files or by destroying your search engine rankings. Study and caution are advised.

Jim

Erwin_D

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

10+ Year Member



Quite simple: Make a virtual host for both subdomains. In the subdomain that you want to redirect, put the following:

<VirtualHost *:80>
ServerName pics.mydomain.com
RedirectPermanent / [media.mydomain.com...]
</VirtualHost>

This will redirect all requests, including files and directories, to the same resource on media.mydomain.com.

Erwin_D

3:09 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



You'll need to use mod_rewrite to do this redirect

No you don't.

Frankly, I see a lot of posts offering mod_rewrite solutions to very simple problems that can be solved without mod_rewrite. Some posters see mod_rewrite as a solution to all problems, which is simply not true.

Mod_rewrite is a powerfull tool, but also very complex and I do feel it is being over-used. I don't know why... maybe because it's l33t or just becuase they don't know any better.

Reading Apache's docs offers many solutions without having to resort to mod_rewrite.

jdMorgan

3:35 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Erwin_D,

Welcome to WebmasterWorld!

I stand corrected. Many of the members posting here do not have access to the http.conf server configuration file. Therefore, their options are limited, and mod_rewrite in .htaccess is often the only solution. In other cases, the answers address a specific question in the context defined by that question.

Mod_rewrite is not required to solve the question posed in this thread if changes can be made at the server config level.

Jim

Erwin_D

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

10+ Year Member



OK, I didn't realize that not everyone has access to httpd.conf, so that leaves .htaccess, provided the host has mod_rewrite, or even .htaccess, enabled.

jadefalcon1

9:21 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



I tried this:
<virtualhost *:80>
servername pics.mydomain.com
redirect permanant / media.mydomain.com
</virtualhost>

And ran it through the tester. Got this:
Syntax error.
Redirect to non-URL. What on earth?

I do have full access to this machine, as it physically lives with me, so edit rights for the server aren't an issue, but the hapless n00b of an administrator that I am does make things a bit more difficult.

storemike

9:34 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



I had a similar issue (with the Non-url). It has to be a fully-qualified one with http and everything.

Try:

Redirect permanent / [media.mydomain.com...]

hth,
Mike

jadefalcon1

10:25 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



Tried that too. Even if I use http://media.example.net in the redirect, it still gives a syntax error.

In the examples of this command, I've noticed that none use the / as the first argument. Is that what's causing the problem?

[edited by: jdMorgan at 10:45 pm (utc) on Mar. 2, 2005]
[edit reason] Obscured specfics. [/edit]

jdMorgan

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

WebmasterWorld Senior Member 10+ Year Member



No, the slash is valid. However, "permanant" is misspelled. Try one of the following:

Redirect 301
Redirect Permanent
RedirectPermanent

Jim

jadefalcon1

12:01 am on Mar 3, 2005 (gmt 0)

10+ Year Member



Wow. I feel dumb now. The spelling error corrected the problem. However, it created another behavior which I wasn't expecting.

When I go to the [pics.mysite.com,...] it gets properly redirected to [media.mysite.com....] However, when I try to access [pics.mysite.com...] the URL does not get redirected to the [media.mysite.com...] as I want.

Am I going to have to use mod_rewrite to do this?

jdMorgan

4:02 am on Mar 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, Redirect [httpd.apache.org] will do what you want by default. Try adding a trailing slash to the new URL.

Jim

jadefalcon1

12:26 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



Awesome! It works like a charm. Thank you all for your help!