Topic: Apache redirect

Noob question:

I have a linux host with Apache, I'd like to make http://forum.myhost.com to redirect to http://www.myhost.com/forum
I'm pretty much sure that it works with mod_rewrite but that seems to be a whole new programming language to me rather than a few parameters. Would anyone be so kind to explain me how to do?

Thanks in advance.

2 (edited by Jérémie 2007-06-07 13:02)

Re: Apache redirect

You could try:

RewriteEngine On
RewriteCond  %{HTTP_HOST}  ^forum\.yourhost\.tld [NC]
RewriteRule  ^/?(.*)  http://yourhost\.tld/forum/$1 [R=301,L]

Meaning "if the host is forum.yourhost.tld (caseless), then rewrite to yourhost.tld/forum/ and add the rest of the URL behind it. And Send a HTTP Redirected Permanently code, so that various UA and bots know it has moved.

Re: Apache redirect

Thanks Jérémie for the help, yet firefox doesn't seem to find the host.
It returns "Server not found".

Re: Apache redirect

Link?

Re: Apache redirect

http://forum.thesk.net/ (which should point to http://www.thesk.net/forum/

Re: Apache redirect

Here's what I use for punbb.org:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^forums.punbb.org$ [NC]
RewriteRule ^(.*)$ http://punbb.org/$1 [R=301,L]
"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Apache redirect

There must be something in the Apache configuration that prevents that since it does not work. Anyhow thanks a lot guys for the help.

Re: Apache redirect

Are you sure mod_rewrite is enabled on the server at all? Check if mod_rewrite is in the loaded modules list for apache when you do a phpinfo().

"Programming is like sex: one mistake and you have to support it for the rest of your life."

9 (edited by Jérémie 2007-06-08 09:26)

Re: Apache redirect

Well, it seems there's no DNS record for this subdomain. It has to exist and be handled by Apache before any rewrite rule can be applied.

C:\>curl -I http://forum.thesk.net
curl: (6) Could not resolve host: forum.thesk.net; Host not found

Re: Apache redirect

Rickard wrote:

Are you sure mod_rewrite is enabled on the server at all? Check if mod_rewrite is in the loaded modules list for apache when you do a phpinfo().

There's not a single entry for Apache in the phpinfo, that might be the reason.

Re: Apache redirect

Jérémie's issue is the more important one

Re: Apache redirect

Oh right, thanks for that Jérémie but it's something I have no idea how to do.

Re: Apache redirect

Ask your hosting company.

But I might say, if the forum. subdomain doesn't exist, why create it only to redirect it elsewhere?

Re: Apache redirect

Jérémie wrote:

But I might say, if the forum. subdomain doesn't exist, why create it only to redirect it elsewhere?

Just because I thought it would look better. Silly reasons though.

Re: Apache redirect

Then why not move your /forum/ to forum. ?

Re: Apache redirect

Jérémie wrote:

Then why not move your /forum/ to forum. ?

Didn't think of that, thanks, I'll give it a try.