mod_rewrite to rewrite HTTP_HOST (subdomains)

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

mod_rewrite to rewrite HTTP_HOST (subdomains)

Post by Luke »

I'm trying to use mod_rewrite to send users to a sub-directory for certain sub-domains. Is there a better way to do this (w/out mod_rewrite)? If not, than how do I rewrite the HTTP_HOST portion of the uri?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

sounds like a job for the httpd.conf to me.. I forget what section though. maybe define a virtualhost?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

i don't have access to it.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

OK, so this rule works:

Code: Select all

RewriteEngine On
# Skip www.mysite.info
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.mysite\.info
RewriteRule ^/(.*)$  /vservers/mysite/htdocs/%1/$1 [L]
But it attaches /blog to the end of the URI in the URL, so I type in blog.mysite.info, and then it redirects me to http://blog.mysite.info/blog. Is there any way to make it not show the /blog part?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Image
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Are you looking for an automated solution? or is this for your own personal usage.

I say this because most hosts will provide a subdomain manager in your hosting control panel which you can define the domain and the folder it points to.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

My host configured the dns so the subdomains would work, but they told me that that's as much as they will do. They said to write a "script" that redirects the user, as in like a PHP script in the index.php... which I find pretty impractical.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Nevermind... this works.

Code: Select all

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(wiki|blog)\.mc2design\.info
RewriteRule ^(.*)$  %1/$1 [L,QSA]
EDIT: now... anybody have any ideas on how to keep requests from http://www.mc2design.info/wiki and http://www.mc2design.info/blog from resolving? I only want those to be accessible via the subdomain. I can't figure out how to make it work. :(
Last edited by Luke on Fri Mar 02, 2007 4:47 pm, edited 3 times in total.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Surely your host provides a control panel of some sort. (cpanel for example)

I.e.: http://jefs.com/nick/Clipboard01.jpg
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

they give you the ability to add sub-domains to point to an IP, but not to a directory. :(
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Doh :(
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Alright, I've got another question related to this...

I've got a subdomain set up at blog.mc2design.com and a subdomain set up at blog.mc2design.info. If blog.mc2design.com is pointed at mc2design.com, what would I have to do in order for somebody to type in blog.mc2design.com and have them resolve to blog.mc2design.info, but never know about it? Is it possible? I've never been able to get this to work.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

So, you want both .info and .com to resolve to the same ip address, so that all requests get sent to the same server?

Add a new entry in your dns system for .info pointing to the same ip address, you will have to ensure that you can add a domain to your hosting account (some hosts charge per month for this).

Other than that, I can't think of anything else you'd be required to do.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Tell me if this resolves for you:
http://blog.mc2design.com/
Post Reply