.htaccess使用动态网址重定向

时间:2010-07-31 19:52:58

标签: apache .htaccess redirect

我在为某些网址重定向时遇到问题,那些来自旧网站的网址有?签名,不会重定向,其他每个URL都会这样做。 例: 旧: /laser-alignment-resources/presentations.cfm?pres=diaphragm

NEW: http://www.acquip.com/en/presentations/47-presentation-internal-laser-diaphragm-alignment

无法正常工作,我确信我做错了但是当谈到.htaccess时我是n00b

所有网址格式相同,共14个:

OLD:/laser-alignment-resources/presentations.cfm PRES =气体 新:http://www.acquip.com/en/presentations/48-presentation-gas-turbine-thermal-alignment

OLD:/laser-alignment-resources/presentations.cfm?pres=train 新:http://www.acquip.com/en/presentations/49-presentation-complete-machine-train-alignment

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您的问题不清楚您是如何尝试在.htaccess文件中执行重定向的,因此下次我建议您发布一些您尝试过的代码示例我们可以更轻松地帮助您。

根据您的Apache标记和您正在描述的问题,我将假设您正在使用mod_alias,尝试执行以下操作:

Redirect 301 /laser-alignment-resources/presentations.cfm?pres=diaphragm http://www.acquip.com/en/presentations/47-presentation-internal-laser-diaphragm-alignment

这不起作用,因为Redirect指令似乎只检查请求的路径部分,而不是查询字符串。

如果您有mod_rewrite可用,则可以根据查询字符串为需要重定向的网址设置重写规则。这看起来像这样:

RewriteEngine On

RewriteCond %{QUERY_STRING} =pres=diaphragm
RewriteRule ^laser-alignment-resources/presentations\.cfm$ http://www.acquip.com/en/presentations/47-presentation-internal-laser-diaphragm-alignment [R=301,L]

RewriteCond %{QUERY_STRING} =pres=gas
RewriteRule ^laser-alignment-resources/presentations\.cfm$ http://www.acquip.com/en/presentations/48-presentation-gas-turbine-thermal-alignment [R=301,L]

......等等。您可以保留当前正在使用的Redirect语句,因为它们应与这些规则并行工作。