Apache Mod重写规则特殊条件

问题描述:

我试图将旧域重定向到它的noew域,但有一些规则,我需要到位,到目前为止我还没有设法让它很正确。Apache Mod重写规则特殊条件

旧域名如www.old-domain.com有数百个文件夹名的英国城镇,如在此之后:

www.old-domain.com/sheffield/ www.old-domain.com/london/ www.old-domain.com/essex/

每个这些文件夹内都包含一个index.html文件以及其他可能的directoreis和文件。

我需要将它们重定向到新域名,以便旧域/城市映射到新域/城镇,但旧域/城镇/ index.html不会将index.html放在新域名末端,但如果小镇之后的路径是index.html以外的任何地方,以便在新域中重定向到它。
对不起,这不是最容易解释,也不是最简单的阅读和undeerstand我确定。

www.old-domain.com/sheffield => www.new-domain.com/sheffield

www.old-domain.com/sheffield/ => www.new-domain.com /谢菲尔德/

www.old-domain.com/sheffield/index.html => www.new-domain.com/sheffield/

www.old-domain.com/sheffield/main.html => www.new-domain.com/sheffield/main.html

www.old-domain.com/sheffield/innerFolder/ => www.new-domain.com/sheffield/innerFolder

www.old-domain.com/sheffield/innerFolder/file.php => www。 new-domain.com/sheffield/innerFolder/file.php

粗体两个以上我设法得到这个工作:

Options +FollowSymLinks 
RewriteEngine on 
RewriteRule ^sheffield/(.*)$ http://www.new-domain.com/sheffield/$1 [R=301,L] 

但我真的努力让old-domain.com/sheffield /index.html不在新域中放置.index.html。

任何人都可以摆脱任何光在这之前我拉着我的头发盯着mod重写教程任何更多的小时?

经过大约4-5小时的尝试不同的梳理和阅读上帝知道我设法到达那里有多少rewriterule教程。下面是只有3个位置的htacess文件,这些文件现在都很好用。

Options +FollowSymLinks 
RewriteEngine on 

RewriteRule ^sheffield\/index\.html http://www.new-domain.co.uk/sheffield/ [R=301,L] 
RewriteRule ^sheffield/(.*)$ http://www.new-domain.co.uk/sheffield/$1 [R=301,L] 

RewriteRule ^bolton\/index\.html http://www.new-domain.co.uk/bolton/ [R=301,L] 
RewriteRule ^bolton/(.*)$ http://www.new-domain.co.uk/bolton/$1 [R=301,L] 

RewriteRule ^coventry\/index\.html http://www.new-domain.co.uk/coventry/ [R=301,L] 
RewriteRule ^coventry/(.*)$ http://www.new-domain.co.uk/coventry/$1 [R=301,L] 
+1

除非你有一些目录将被不同地转发,我会试图进一步简化它: RewriteRule ^(。*)\/index \ .html http://www.new-domain.co。英国/ $ 1/[R = 301,L] RewriteRule ^(。*)$ http://www.new-domain.co.uk/$1 [R = 301,L] – 2012-07-27 09:53:51

+0

谢谢德国人。我看到你的逻辑。我不能在一分钟内做到这一点,因为我们并没有一次性重定向所有的位置。这里的博客对搜索引擎优化排名相当困扰,所以我们已经完成了大约3500个地点的10个地点。然而,当我们完全交换时,我一定会回来看看你的例子。感谢你的宝贵时间。 – azzy81 2012-08-01 15:34:18

提示:重写规则在第一个匹配的基础上进行处理。 你可以把你的例外主要规则

+0

感谢您的支持。 Mod Rewrite就像一个复杂的雷区。它与正则表达式一样......只是大量复杂的规则和随机的行话几乎每次都需要很长时间才能获得所需的确切模式。但是我确实已经完成了,下面是我所做的。 – azzy81 2012-07-27 09:36:21