用htaccess重写和重定向

时间:2017-04-26 15:44:19

标签: .htaccess mod-rewrite

客户要求我们将旧域(bcsbd.com)中的所有内容复制到其主域(ywcacam.org),并创建重定向,以便旧URL仍可正常运行。不幸的是,网址并不完全匹配,例如,[olddomain] / about已成为[newdomain] / about_soo_bahk_do。要处理的特定URL少于10个,我们最初使用旧域的htaccess文件中的Redirect语句成功执行了此操作:

# redirect specific pages to page on new domain
Redirect /about http://www.ywcacam.org/about_soo_bahk_do

我们还需要一个全能,以便任何其他请求转到新域上的特定URL,例如www.bcsbd.com/somefile变为www.ywcacam.org/soo_bahk_do。我们使用Rewrite语句处理了这个:

# catch-all for any requests not specified above
RewriteCond %{HTTP_HOST} ^(bcsbd.com|www.bcsbd.com) [NC]
RewriteRule ^(.*)$ http://www.ywcacam.org/soo_bahk_do [L]

快速研究显示Rewrite指令(使用mod_rewrite)将始终在Redirect指令之前处理(使用mod_alias)。所以我们用重写代替了重定向:

Options +FollowSymlinks
RewriteEngine On
RewriteRule /about http://www.ywcacam.org/about_soo_bahk_do [L]
RewriteRule /programs http://www.ywcacam.org/programs_soo_bahk_do [L]
...

# catch-all for any requests not specified above
RewriteCond %{HTTP_HOST} ^(bcsbd.com|www.bcsbd.com) [NC]
RewriteRule ^(.*)$ http://www.ywcacam.org/soo_bahk_do [L]

问题在于,只有catch-all正在运行 - 新的Rewrite规则被忽略了。我们在这些陈述中做错了什么?

提前感谢您的帮助!

0 个答案:

没有答案