Two domains, same www root but different URI's

Using a single web hosting account to host multiple sites

Two domains, same www root but different URI's

Postby zoot » Fri Jun 13, 2008 5:29 am

Hi all!

I'm trying to set up a rewrite rule for a domain (www.domain2.com). I've already got a domain (www.domain1.com) pointing to the same server and document root. So this second domain (www.domain2.com) is a ServerAlias.

The site is drupal driven with clean URL's activated. That means that I already have rewrite rules in my conf. This is the rewrite rule that I currently have:

Code: Select all
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


I've written a new module that's accessed at this URL (and this is with drupal's rewrite rule):

www.domain1.com/movies/search

without drupal's rewrite rule it is accessed here:

www.domain1.com?q=movies/search

When I do a search on this page it will append that to the end like this:

www.domain1.com/movies/search?var1=test&var2=hello

What I want now is to have a rewrite rule that rewrites:

Code: Select all
www.domain1.com/movies/search or www.domain1.com?q=movies/search

into

www.domain2.com/

and with a search

www.domain2.com/?var1=test&var2=hello


This is what I came up with (it obviously doesnt work):

Code: Select all
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=movies/search$1 [L,QSA]


I've also tried to combine this rule with drupal's like this:

Code: Select all
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ movies/search$1 [QSA]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


But as I said it won't work like I want it to :/

Anyone out there who can help me, I would really appriciate it!
zoot
 
Posts: 2
Joined: Fri Jun 13, 2008 3:44 am

Postby richardk » Fri Jun 13, 2008 2:10 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.domain2\.com$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?q=movies/search$1 [QSA,L]

RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?q=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby zoot » Mon Jun 16, 2008 1:48 am

Thanks for the reply!

I've tried to set it up like you said (and different variations of it). It works partially. When I visit www.domain1.com or www.domain2.com (at root level), none of the rules is executed. But if I throw in a character after www.domain2.com/f then I end up on index.php?q=movies/search/f. I can't figure out why the rule isnt executed when only visiting www.domain2.com.

If I set a rule like this:
Code: Select all
RewriteCond %{HTTP_HOST} ^www\.domain2\.com [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ http://www\.domain2\.com/index.php?q=movies/search/$1 [QSA,L]

Then it rewrites to the correct url and shows the correct page, but then I have index.php?q=movies/search in the url and that's not what I want. Do you have any suggestions?

Thanks!
zoot
 
Posts: 2
Joined: Fri Jun 13, 2008 3:44 am

Postby richardk » Thu Jun 19, 2008 1:22 pm

Try replacing both
Code: Select all
RewriteCond %{SCRIPT_FILENAME} !-d

with
Code: Select all
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{SCRIPT_FILENAME} !-d
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 17 guests

cron