Web Hosting Talk







View Full Version : Need .htaccess redirection


Spunky
05-16-2002, 06:47 AM
Hello!

I urgently need the following .htaccess file:

As my host doesn't automatically support the creating of subdomains, I want to setup a .htaccess file for that. He said, that he can enable for forwarding for *.mydomain.com to www.mydomain.com. Now I need a .htaccess file which regognizes the URL a visitor came from and forwards him to www.mydomain.com/directory.

So when a user types in:

http://whatever.mydomain.com

He gets redirected to:

http://www.mydomain.com/whatever

Would be great if anyone of you has this script.

Will this be possible too using .htaccess?

http://i.can.write.anything.here.mydomain.com

to

http://www.mydomain.com/here

???

Thanks a lot!!!

webx
05-16-2002, 10:03 AM
First of all you need to have DNS setup to resolve whatever.yourname.com.

Secondly you need mod_rewrite enabled on your Apache. Then you can do this:


RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?whatever\.yourname\.com$ [NC]
RewriteCond $1 !whatever/
RewriteRule ^/?(.*)$ /whatever/$1 [L]


and enjoy :)

Spunky
05-20-2002, 01:15 PM
Thanks masood!

My provider has set up the DNS that way:

*.mydomain.com goes to www.mydomain.com

So as I am not a .htaccess guru, how can I change your .htaccess file, so that it works for all subdomains?

webx
05-20-2002, 01:21 PM
You just have to change "whatever" to appropriate values and repeat the last three lines for each entry.

Spunky
05-20-2002, 01:23 PM
Oh my...

So that will result in a really big .htaccess file :(

Isn't there a possibility to set that up with a few lines for each subdomain?

If not, I'll :bawling:

webx
05-20-2002, 01:28 PM
OK, then you can try reading this "small" document:

http://httpd.apache.org/docs/mod/mod_rewrite.html

and let me know as well ;)

:D

Spunky
05-21-2002, 05:38 AM
What about this one? It seems to be doing that what I want. Couldn't test it yet, as I still don't have the hosting account set up.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C?]
RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2