• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 849
  • Last Modified:

rewritecond if is serveralias

Hi, i want do a rewrite in apache that the unique condition if the host is one of the different serveralias (more than 90 domains).
How i can do it without use a rewritecond line per each domain.

1 Solution
David S.Commented:
You can check if the hostname is not one of the ones you don't want to perform the rewrite for. Something like this:
RewriteCond %{HTTP_HOST} !www.primaryhost.com$

Open in new window

Something like this :

RewriteCond %{HTTP_HOST}   !^www\.mydomain\.com [NC]
RewriteRule ^/(.*)         http://mydomain.com/$1 [L,R]

soyglobalAuthor Commented:
I know this way, but the problem is that rule not apply to all server alias,
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Where do you add this rule ? .htaccess file or apache configuration ?
soyglobalAuthor Commented:
Apache configuration in virtualhost
perhaps your rewrite rule is overriden by a .htaccess file
soyglobalAuthor Commented:
the problem not is that rewrite failed, my problem is how manage a rewritecond with near 75 conditionals
rewritecond  %{HTTP_HOST}= domain1 or
rewritecond  %{HTTP_HOST}= domain2 or
rewritecond  %{HTTP_HOST}= domain75 or
rewrite from / to the moon.foo
I think apache should has a way for do it more simple and fast
What exactly do you want ? give us some samples.

foo.bar.com => www.bar.com  ?
bla.bla.com => bla.com ? ...

You can certainly achieve this with some regex
soyglobalAuthor Commented:
I need some this:
if http_host = one of 75 group1 alias domain go to www.foo.com
if http_hots = one of 20 group2 alias domain go to www.blaba.com
the problem is the number of values to check (75 and 20), and increasing per month
What about using 4 different <virtualhost *:80> sections? One for www.foo.com, one for www.blaba.com,  one for aliases of www.foo.com and one for aliases of www.blaba.com; while you put a simple

Redirect 301 / http://www.foo.com

into the "alias" <virtualhost >'s instead of brothering with mod_rewrite.
soyglobalAuthor Commented:
because i don't want do a redirect, i need have as i put before
rewrite on
rewritecon http-referrer = one of group1 alias
rewriteurl (.)*  http://bkjkj.com/?redirect-host=http-referrer qsa, l

rewritecon http-referrer = one of group2 alias
rewriteurl (.)*  http://app.foo.com/?redirect-host=http-host qsa, l

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now