.htaccess使用动态网址重定向

.htaccess使用动态网址重定向

问题描述:

我在为某些网址做重定向时遇到问题,那些来自旧网站的网址有一个?登录,不会重定向,其他每个网址都会执行。 例如: OLD: /laser-alignment-resources/presentations.cfm?pres=diaphragm.htaccess使用动态网址重定向

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

都不行,我相信我做错了什么事,但我是一个的n00b当涉及到的.htaccess

所有网址都在相同的格式,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

任何帮助将不胜感激。

你的问题并不清楚你如何试图在你的.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报表,因为它们应该与这些规则并行良好地工作。

+0

对不起,如果我不清楚,但你实际上已经发现它很好,我使用301重定向而不是mod_rewrite。 我刚刚尝试使用mod_rewrite,它也不能正常工作。 我打电话给托管公司,他们说他们在他们的服务器上启用了mod_rewrite。 它还能是什么? – Terumo 2010-08-04 16:47:50

+0

没问题,我只是想确保我提供了一个对你有用的答案。至于它不工作,我不知道为什么它不应该,但我今天下班后会进行调查,看看我能否提出一个替代解决方案。 – 2010-08-05 10:28:01

+0

@Terumo - 嗯,它可以在我的测试服务器上正常工作。当您访问连接了查询字符串的URL时,什么都不会发生?你可以测试'mod_rewrite'通常使用像'RewriteRule^rewrite-test $ http://stackoverflow.com/ [R = 301,L]'这样的规则并转到那个'rewrite-test' URL并看到如果你被重定向到堆栈溢出。 – 2010-08-06 04:06:43