sub.dom.com/dir -> www.dom.com/index.php?page=sub-dir

Using a single web hosting account to host multiple sites

sub.dom.com/dir -> www.dom.com/index.php?page=sub-dir

Postby RealmWorx » Tue Sep 12, 2006 1:01 pm

I provide a free forum hosting service, and went to create semi-custom homepage for each of my clients (done via the $_GET[page]). What I was wondering is if there was a way to do this:

sub.domain.com/dir -> www.domain.com?page=sub-dir

I was thinking something liek this would work, but the directory isn't part of the HOST address to get the 2nd variable.

RewriteCond %{HTTP_HOST} !^www\.domain\.com?$
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com/([^.]+)?$
RewriteRule ^$ /index.php?page=%1-%2 [L]

Thanks!
RealmWorx
 
Posts: 4
Joined: Fri Sep 01, 2006 6:49 am

Postby richardk » Tue Sep 12, 2006 1:33 pm

Close. %{HTTP_HOST} only contains the domain, not the rest if the URL, and ^$ will only allow it to match domain.tld/ (no subdirectories/files).

I assume you have DNS setup and these subdomains are pointed to the dircetory with the .htaccess file in it. Try this:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST}     !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^([^\.]+)/?$   /index.php?page=%1-$1  [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby RealmWorx » Tue Sep 12, 2006 1:45 pm

I got so close before you replied! :) I'm really loving the power behind mod_rewrite, and you are definately a lifesaver. Thanks!
RealmWorx
 
Posts: 4
Joined: Fri Sep 01, 2006 6:49 am

Postby Dexterz » Wed Nov 01, 2006 12:04 am

Hi,
I just joined the forum and this is my first time working with mod rewrite. I was searching for my problem which is similar to this thread.
I want to do the following rewriting
www.anything.domain.com/ -> www.domain.com/action.asp?page=anything

I do not have any DNS entry or actual directory structure of "anything" because it can be anything! :D Is it possilbe to do what I am trying? I did try
Code: Select all
RewriteCond %{HTTP_HOST}     !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^([^\.]+)/?$   www.domain.com/action.asp?page=%1  [L]


This gives me "The page can not be displayed" :(
Looking forward to some feedback for the newbie 8)

Regards

[edit] Further discussion about this problem is here. richardk [/edit]
Dexterz
 
Posts: 6
Joined: Tue Oct 31, 2006 11:25 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 70 guests

cron