views:

13

answers:

1

I have the following in my .htaccess currently-

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^go/([^/]*)/([0-9]+)/([0-9]+)/?$ http://foo.com/wp-content/plugins/foo/cloak.php?post_id=$2&amp;link_num=$3&amp;cloaked_url=$0 [L]
RewriteRule ^go/([^/]+)[/]?$ http://foo.com/wp-content/plugins/foo/cloak.php?name=$1&amp;cloaked_url=$0 [L]
</IfModule>

I want to change it so that the domain 'http://foo.com' is auto-detected and inserted (or just left off if it's unnecessary.

I'm hoping to use this .htaccess to manage multiple mapped domains to the same code base and can't really have it work with a specific URI in there.

+1  A: 

Use RewriteCond for that:

RewriteCond %{HTTP_HOST} !^foo.com$
RewriteRule ...
Ignacio Vazquez-Abrams
That makes sense. So i would basically just write a section like above for each domain i want to address in the .htaccess?Do i have to do separate sections RewriteRules for each RewriteCond or is there a way to have all RewriteConds use the same rule?
Marty
So like this?-RewriteCond %{REMOTE_HOST} ^host1.* [OR]RewriteCond %{REMOTE_HOST} ^host2.* [OR]RewriteCond %{REMOTE_HOST} ^host3.*RewriteRule ...
Marty
You can use the `OR` flag on `RewriteCond` to logically-or the conditions, but mod_rewrite doesn't support any sort of branching.
Ignacio Vazquez-Abrams
So I believe if I read it correctly your example is "Does not match foo.com"? Let's say that returns true. How do I format my `RewriteRule` to leave off the HTTP_HOST (or whatever the equivalent is for the- http://foo.com)? Thanks I appreciate your help, REGEX and rewrites have never been my strong suit!
Marty
Marty
Your error log should tell you what caused the 500.
Ignacio Vazquez-Abrams
Unfortunately it is empty
Marty
Maybe it doesn't like that `cloaked_url` is unencoded. Try removing chunks of the stanza until it stops returning a 500.
Ignacio Vazquez-Abrams
I actually just realized (duh), if I just remove `http://foo.com` from the `RewriteRule` that it works just fine for all the domains mapped to this codebase. I'm going to bookmark your answer though because I will probably need it sometime soon. Thanks so much for your time!!
Marty