Forum Moderators: phranque
Can anyone please help me on the problem described below?
I have a number of sub domains under the domain - example.com as product1.example.com, product2.example.com, product3.example.com etc
Both example.com and product1.example.com has web pages with same URL except the domain name
Example
http://example.com/abc/picture.html
http://product1.example.com/abc/picture.html
I have to redirect http://example.com/abc/picture.html to http://example.com/abc/new.html if the request is from example.com. It should not get redirected if the request is from any of its sub domains (product1.example.com)
I have mapped all my sub domains as shown below. The redirect rule which I used is also mentioned.
<VirtualHost xx.xx.xx.xx>
RewriteEngine On
DocumentRoot /web/xyz
ProxyPreserveHost On
RewriteCond %{HTTP_HOST} ^product1\.example\.com [NC]
RewriteRule .* - [L]
RedirectMatch permanent /abc/picture.html /abc/new.html
ProxyPassMatch /abc/picture.html !
ProxyPass / balancer://xyzcluster/
ServerName example.com
ServerAlias www.example.com
ServerAlias product1.example.com
</VirtualHost>
<Proxy balancer://xyzcluster>
BalancerMember http://yy.yy.yy.yy:80
..........
</Proxy>
Thanks
Abhilash Gopinath
[edited by: jdMorgan at 3:16 pm (utc) on Feb. 12, 2009]
[edit reason] example.com [/edit]
Change the RedirectMatch line to a RewriteRule (note that the syntax differs markedly), and the function you expected will likely work. Note also that it could be recoded more simply using only two lines as
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^/abc/picture\.html$ http://example.com/abc/new.html [R=301,L]
---
Both example.com and product1.example.com has web pages with same URL except the domain name.
One way to look at it is like a car race: Do you want to enter two cars in the race, each with a 200 horsepower engine, or one with a 400 horsepower engine?
Jim
[edited by: jdMorgan at 3:17 pm (utc) on Feb. 12, 2009]
Thanks a lot for the solution and it worked!.
I actually wanted to do a negative condition.
I wanted to do a redirect if the domain is company.com, else skip the redirects, and actually I had to do many redirects from this domain, so I did the following
RewriteCond %{HTTP_HOST} !^company\.com [NC]
RewriteRule .* - [S=354]
Include conf/MyRedirects.conf
where all my 354 redirects are included in MyRedirects.conf
in a format as you mentioned above and it worked.
I saw your solution on skipping redirects at
[webmasterworld.com...]
Thanks again
Abhilash Gopinath
I have one more problem as mentioned below.
I have to redirect to a new website http://example.com/index.html if the user enters
product1.example.com or
product1.example.com/
http://product1.example.com/
But if the user invokes a valid page on product1.company.com it should get served from product1.company.com itself.
I have defined a valid page as any URL with a period and added a redirect rule in the httpd.conf of product1.example.com as shown below.
RedirectMatch permanent ([/]*(^[^.]*$)) http://example.com/index.html
But it didn't work for Servlets since they don't have a period!
Any solutions on the top of your head Jim?
Thanks
Abhilash
[edited by: jdMorgan at 3:20 pm (utc) on Feb. 12, 2009]
[edit reason] example.com [/edit]
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule !^/([^/]+/)*[^.]+\. http://example.com/ [R=301,L]
Jim
[edited by: jdMorgan at 3:19 pm (utc) on Feb. 12, 2009]