将特定但通配符* URL(带文件夹)重定向到新域(相同结构)

时间:2015-02-12 17:45:21

标签: .htaccess iis helicontech

我需要使用新域将特定网址(带结构)重定向到相同的网址,而不是其他网址。

domainA.com/company/careers *

domainB.com/company/careers *

原因是第三方供应商提供基于jquery的iframe应用程序,该应用程序在加载前执行引荐来源检查。

我意识到有一个更大的seo /重复内容问题需要解决,但是在domainA.com完全重定向到domainB.com之前还需要做很多额外的工作,所以现在,它只有“职业”部分。

该网站正在使用IIS6和HeliconTech的ISAP ReWrite3

http://www.helicontech.com/isapi_rewrite/doc/introduct.htm

现行规则:

# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.59

<VirtualHost www.domainA.com www.domainB.com> 

RewriteEngine On 

#RewriteBase /
#RewriteRule ^pubs/(.+)\.pdf$ /404/?pub=$1.pdf [NC,R=301,L]

# Send away some bots
RewriteCond %{HTTP:User-Agent} (?:YodaoBot|Yeti|ZmEu|Morfeus\Scanner) [NC] 
RewriteRule .? - [F]

# Ignore dirctories from FarCry Friendly URL processing
RewriteCond %{REQUEST_URI} !(^/measureone|^/blog|^/demo|^/_dev)($|/) 
RewriteRule ^([a-zA-Z0-9\/\-\%:\[\]\{\}\|\;\<\>\?\,\*\!\@\#\$\ \(\)\^_`~]*)$ /index.cfm?furl=$1 [L,PT,QSA] 

RewriteCond %{REQUEST_URI} ^/company/careers [NC]
RewriteRule ^company/careers/?(.*)$ http://www.domainname.com/company/careers/$1 [R=301,L]

# Allow CFFileServlet requests
RewriteCond %{REQUEST_URI} !(?i)^[\\/]CFFileServlet


RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /blog/index.php [L]

</VirtualHost> 

<VirtualHost blog.domainA.com> 

RewriteEngine On 

#redirect old blog.domainA.com/* posts to www.domainB.com/blog/*
RewriteCond %{HTTP_HOST} ^blog.domainA\.com [nc]
RewriteRule (.*) http://www.domainB.com/blog$1 [R=301,L]


</VirtualHost> 

2 个答案:

答案 0 :(得分:1)

只需检查请求是否以/company/careers

开头
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/company/careers [NC]
RwriteRule ^company/careers/?(.*)$ http://domainB.com/company/careers/$1 [R=301,L]

看看它是否适合你。

答案 1 :(得分:1)

似乎“RewriteBase / blog /”行会破坏您的“职业”规则,因为它暗示请求应该是domainA.com/blog/company/careers *

请考虑这样做:

<VirtualHost www.domainA.com www.domainB.com> 

RewriteEngine On 
RewriteBase /
#RewriteRule ^pubs/(.+)\.pdf$ /404/?pub=$1.pdf [NC,R=301,L]

# Send away some bots
RewriteCond %{HTTP:User-Agent} (?:YodaoBot|Yeti|ZmEu|Morfeus\Fucking\Scanner) [NC] 
RewriteRule .? - [F]

# Ignore dirctories from FarCry Friendly URL processing
RewriteCond %{REQUEST_URI} !(^/measureone|^/blog|^/demo|^/_dev)($|/) 
RewriteRule ^([a-zA-Z0-9\/\-\%:\[\]\{\}\|\;\<\>\?\,\*\!\@\#\$\ \(\)\^_`~]*)$ /index.cfm?furl=$1 [L,PT,QSA] 

RewriteCond %{REQUEST_URI} ^/company/careers [NC]
RewriteRule ^company/careers/?(.*)$ http://www.domainname.com/company/careers/$1 [R=301,L]

# Allow CFFileServlet requests
RewriteCond %{REQUEST_URI} !(?i)^[\\/]CFFileServlet

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/.* /blog/index.php [L]

</VirtualHost> 

如果仍有问题,请通过添加

启用httpd.conf中的日志记录
RewriteLogLevel 9

并检查您的请求在rewrite.log中的处理方式。