domain handling problem

Using a single web hosting account to host multiple sites

domain handling problem

Postby outlawbt » Mon Mar 16, 2009 10:16 am

Hello, I have a problem that I want to solve with htaccess and il'' describe it with this example:
Let's suppose that I have 3 domains:

www.maindomain.com
www.otherdomain.com
www.otherdomain2.com

All of the domains point to the same root of my Kohana Framework Application.
I want when I access the maindomain.com the index.php to be executed normally.
When I access the otherdomain.com the index.php/otherdomain to be executed,
and when I access the otherdomain2.com the index.php/otherdomain2 to be executed.

This is like passing the domain names to the php script like parameters.
The current Kohana htaccess that passess all requests to the index.php file looks like this:
Code: Select all
# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /MyApp/

# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]


Thanks in advance
outlawbt
 
Posts: 4
Joined: Mon Mar 16, 2009 10:06 am

Postby richardk » Tue Mar 17, 2009 2:11 am

What about a request to otherdomain.com/abc?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(application|modules|system)(/.*)?$ - [F,L]

RewriteCond %{HTTP_HOST}/otherdomain ^(www\.)?otherdomain\.com(/otherdomain)$ [NC,OR]
RewriteCond %{HTTP_HOST}/otherdomain2 ^(www\.)?otherdomain2\.com(/otherdomain2)$ [NC]
RewriteRule ^$ /MyApp/index.php%2 [L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule .* /MyApp/index.php/$0 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby outlawbt » Tue Mar 17, 2009 12:01 pm

richardk wrote:What about a request to otherdomain.com/abc?

Omg i didn't thought about that :o Thank you very much,your code worked for me, but i like it to be dynamic for all domains.
So, finally, the code should do this:
When I access my maindomain.com, the index.php to be executed normally.
When I access my anyotherdomain.(com,net,org, etc...), the index.php to be executed like this -> index.php/anyotherdomain.
When I access my anyotherdomain.(com,net,org, etc...)/somerequest, the index.php to be executed like this -> index.php/anyotherdomain/somerequest.
I tried to do this but with no luck, so I need your help.
Thanks in advance
outlawbt
 
Posts: 4
Joined: Mon Mar 16, 2009 10:06 am

Postby richardk » Tue Mar 17, 2009 3:00 pm

Try replacing
Code: Select all
RewriteCond %{HTTP_HOST}/otherdomain ^(www\.)?otherdomain\.com(/otherdomain)$ [NC,OR]
RewriteCond %{HTTP_HOST}/otherdomain2 ^(www\.)?otherdomain2\.com(/otherdomain2)$ [NC]
RewriteRule ^$ /MyApp/index.php%2 [L]

with
Code: Select all
RewriteCond %{HTTP_HOST} !^(www\.)?maindomain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.(.+)\.(com|net|org)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(.+)\.(com|net|org)$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /MyApp/index.php/%1/$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby outlawbt » Wed Mar 18, 2009 4:22 pm

This code is close to the solution but it is still not 100% functional.

In the first case when I access maindomain.com everything is OK.

In the second case when I access anyotherdomain.com the script executes normaly same as in the first case (just index.php) , not as i wanted: -> index.php/anyotherdomain

In the third case when I access anyotherdomain.com/somerequest the script executes like it should do: -> index.php/anyotherdomain/somerequest , so that's OK.

So, the problem is only in the second case.
outlawbt
 
Posts: 4
Joined: Mon Mar 16, 2009 10:06 am

Postby richardk » Thu Mar 19, 2009 10:24 am

Code: Select all
RewriteCond %{HTTP_HOST} !^(www\.)?maindomain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.(.+)\.(com|net|org)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(.+)\.(com|net|org)$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /MyApp/index.php/%1/$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 22 guests

cron