2013-08-03 62 views
0

需要将一百个左右的链接从一个域重定向到另一个域。这是我当前的代码(不工作):htaccess运动链接重定向

RewriteCond %{HTTP_HOST} ^www.onedomain.info/$1/staticword($2.*) [nc] 
RewriteRule (.*) http://otherdomain.com/$1/staticword($2.*) [R=301,L] 

重定向域themsleves是一个没有脑子,这就是正确的,我认为,那我也觉得$ 1正确 - 的Cuz $ 1是对12个不同的字变量体育类别(如足球或曲棍球),有时有一个词,有时是另一个词(但是它应该是相同的,所以这就是为什么我有这个1美元 - 如果我错了,纠正我,但这可以工作,我认为。 ..)。

问题是之后有一个不变的静态词(在每个链接中都一样 - 它就像“看”一样......)但是在那个词之后,可以绝对是我试过的任何东西由($ 2. *)解决,但由于某种原因是错误的。

你能帮忙吗?谢谢!

+0

有在你的代码中的许多问题,但在此之前,我可以纠正他们,我会要求您提供新旧链接样本。 – anubhava

+0

目前的链接看起来像这样(例如足球比赛之一):'http:// onedomain.info/soccer/watchfe27789-mexico-vs-trinidad-and-tobago-gold-cup' - “watch”永远不会改变和“fe27789”是每个链接唯一的标识符,与“墨西哥vs特立尼达”相同 - 需要切换到: 'http://otherdomain.com/soccer/watchfe27789-mexico-vs-trinidad-and- tobago-gold-cup' - 它只能用于这个URL形式的链接(有其他类型的内部链接 - 例如onedomain.info/something,所以不希望它们被重定向,不能使用任何一般的“domain”域名“重定向) – Mordor

回答

0
RewriteEngine On 

# HTTP_HOST if to match domain names only 
RewriteCond %{HTTP_HOST} ^www\.onedomain\.info$ [NC] 
# On the left hand we match the rest and on the right we redirect 
RewriteRule ^(.*)/(staticword.*)/?$ http://otherdomain.com/$1/$2 [R=302,L] 

请注意,我用的302,因为你想将其更改为301,您的浏览器没有得到它之前缓存首先测试它,直到你确信它的工作,你想要它。

所以给你的榜样http://onedomain.info/soccer/watchfe27789-mexico-vs-trinidad-and-tobago-gold-cu‌​p,规则是这样的:

RewriteEngine On 

# HTTP_HOST if to match domain names only 
RewriteCond %{HTTP_HOST} ^www\.onedomain\.info$ [NC] 
# On the left hand we match the rest and on the right we redirect 
RewriteRule ^(.*)/(watchfe27789.*)/?$ http://otherdomain.com/$1/$2 [R=302,L] 
+0

工程就像一个魅力,谢谢你! (只注意'fe27789'不应该在那里,因为它每次都是不同的 - 它是唯一的ID,每个不同的链接都在改变,但是当我只将这个部分减少到'(watch。*)'时,全部都是工作完美,很棒的工作......!) – Mordor

+0

@Moror很高兴它适合你,没关系,我只是用它作为你看到如何应用它的一个例子。 – Prix