1

I have 2 domain pointing to same directory, Now I want to redirect some URLs to one specific domain and rest should be on main domain.

I have one domain www.xyz.com this is main domain site will be open with this domain, from this domain I want to redirect specific URLs to different domain so if someone open www.xyz.com/a/theatre then it should redirect to www.abc.com/a/theatre. And now from same this new domain if someone click on URL which don't have "/a/theatre" in URL then it should redirect back to main domain. So if someone open www.abc.com/a/classes then it should redirect to www.xyz.com/a/classes

I have used bellow rules but not working,

RewriteCond %{HTTP_HOST} ^www.xyz.com$ [NC]    
RewriteCond %{REQUEST_URI} ^/a/theatre$    
RewriteRule (.*)$ http://www.abc.com/a/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.abc.com$ [NC]    
RewriteCond %{REQUEST_URI} !^/a/theatre    
RewriteRule (.*)$ http://www.xyz.com/a/$1 [NC,L,R=301]

Any help is appreciated. Thanks!

Here is all code from my htaccess, I have installed Joomla on this domain.

Options -Indexes

RewriteEngine on
RewriteBase /seo
RewriteCond %{HTTP_HOST} ^www.mcleancenter.org$ [NC]
RewriteCond %{REQUEST_URI} ^/seo/alden-theatre$
RewriteRule ^/?seo/(.*)$ http://www.aldentheatre.org/seo/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.aldentheatre.org$ [NC]
RewriteCond %{REQUEST_URI} !^/seo/alden-theatre
RewriteRule ^/?seo/(.*)$ http://www.mcleancenter.org/seo/$1 [NC,L,R=301]

########## Begin - Joomla! core SEF Section
#
#RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section
4

1 回答 1

1

您需要通过在规则中的正则表达式前面/a/添加 a来匹配前导。^/?a/

RewriteCond %{HTTP_HOST} ^www.xyz.com$ [NC]    
RewriteCond %{REQUEST_URI} ^/a/theatre$    
RewriteRule ^/?a/(.*)$ http://www.abc.com/a/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.abc.com$ [NC]    
RewriteCond %{REQUEST_URI} !^/a/theatre    
RewriteRule ^/?a/(.*)$ http://www.xyz.com/a/$1 [NC,L,R=301]
于 2012-08-27T07:37:11.223 回答