6

I have a Drupal site, example.com, and our client has a campaign that they're promoting for which they've bought a new domain name, campaign.com. I'd like it so that a request for campaign.com internally rewrites to a particular page of the Drupal site. Note Drupal uses an .htaccess file in the document root.

The normal Drupal rewrite is

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 

I added the following before the normal rewrite.

# Custom URLS (eg. microsites) go here RewriteCond %{HTTP_HOST} =campaign.com RewriteCond %{REQUEST_URI} =/ RewriteRule ^ index.php?q=node/22 [L] 

Unfortunately it doesn't work, it just shows the homepage. Turning on the rewrite log I get this.

1. [rid#2da8ea8/initial] (3) [perdir D:/wamp/www/] strip per-dir prefix: D:/wamp/www/ -> 2. [rid#2da8ea8/initial] (3) [perdir D:/wamp/www/] applying pattern '^' to uri '' 3. [rid#2da8ea8/initial] (2) [perdir D:/wamp/www/] rewrite '' -> 'index.php?q=node/22' 4. [rid#2da8ea8/initial] (3) split uri=index.php?q=node/22 -> uri=index.php, args=q=node/22 5. [rid#2da8ea8/initial] (3) [perdir D:/wamp/www/] add per-dir prefix: index.php -> D:/wamp/www/index.php 6. [rid#2da8ea8/initial] (2) [perdir D:/wamp/www/] strip document_root prefix: D:/wamp/www/index.php -> /index.php 7. [rid#2da8ea8/initial] (1) [perdir D:/wamp/www/] internal redirect with /index.php [INTERNAL REDIRECT] 8. [rid#2da7770/initial/redir#1] (3) [perdir D:/wamp/www/] strip per-dir prefix: D:/wamp/www/index.php -> index.php 9. [rid#2da7770/initial/redir#1] (3) [perdir D:/wamp/www/] applying pattern '^' to uri 'index.php' 10.[rid#2da7770/initial/redir#1] (3) [perdir D:/wamp/www/] strip per-dir prefix: D:/wamp/www/index.php -> index.php 11.[rid#2da7770/initial/redir#1] (3) [perdir D:/wamp/www/] applying pattern '^(.*)$' to uri 'index.php' 12.[rid#2da7770/initial/redir#1] (1) [perdir D:/wamp/www/] pass through D:/wamp/www/index.php 

I'm not used to mod_rewrite, so I might be missing something, but comparing the logs from a call to http://example.com/node/3 and from http://campaign.com/ I can't see any meaningful difference. Specifically the URI and args on line 4 seem correct, the internal redirect on line 7 seems right, and the pass through on line 12 seems right (because the file index.php exists). But for some reason it seems the query string's been discarded/ignored around the time of the internal redirect. I'm completely stumped.

Also, if anyone could provide a reference on understanding the rewrite log, that might help. It'd be great if there's a way to track the query string through the internal redirect.

FWIW I'm using WampServer 2.1 with Apache 2.2.17.

5
  • i think your RewriteLog level is too low and leaving out RewriteCond comparisons. When you make any substitution in per-directory/htaccess context, the entire ruleset will run again, so the default rule you mention might stomp on your rule you've inserted the 2nd time around. Commented Feb 26, 2011 at 19:29
  • Thanks, I thought I was already at the maximum level, but checking the docs that's 9 and I'm way below that. Will see if the more detailed log helps me, and if not I'll post it here. Thanks again. Commented Feb 27, 2011 at 11:20
  • If you're registering a new domain, couldn't you set up page where at that location and do a redirect to any page/link in your current site? Commented May 5, 2011 at 16:19
  • @digit1001 - I was looking for an internal rewrite, rather than an external redirect. (But I ran out of time and handled it as a redirect in the end!) Commented May 6, 2011 at 9:01
  • I facing the same situation and still not quite sure what i need to do? Andy, have u figured it all out? thx Commented Jun 29, 2011 at 8:08

1 Answer 1

5

The httpd.conf for campaign.com with it pulling data from example.com/macguffin/

<VirtualHost *:80> ServerName campaign.com <Proxy *> Order deny,allow Allow from all </Proxy> ProxyRequests Off ProxyPreserveHost Off ProxyPass / http://example.com/macguffin/ ProxyPassReverse / http://example.com/macguffin/ <Location /> Order allow,deny Allow from all </Location> </VirtualHost> 
2
  • thanks, I've not played with the Proxy related directives before. Do you know if it's impossible to do what I was trying just with mod_rewrite? Commented Jun 23, 2011 at 10:15
  • At the end of the day you want it to be campaign.com instead of mac.guffin.com/mac/guffin/123 that appears in the URL address bar of people's browsers. The only way to do that is with Proxy and its related cousins ProxyPassReverse (unless you are hiding the URL with iframe). This will double your bandwidth at campaign.com but this will not be a problem if that is on loopback of your host. Commented Jun 23, 2011 at 11:20

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.