简体   繁体   English

.htaccess使用动态URL重定向

[英].htaccess redirects with dynamic URLs

I am having problems doing a redirect for some URLS, the ones from the old site that have a ? 我在重定向某些URL时遇到问题,旧站点中的URL带有?? sign, won't redirect, every other URL will do. 签名,不会重定向,其他所有URL都可以。 example: OLD: /laser-alignment-resources/presentations.cfm?pres=diaphragm 例如:OLD:/laser-alignment-resources/presentations.cfm?pres=diaphragm

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

Won't work, I am sure I did something wrong but I am a n00b when it comes to .htaccess 无法正常工作,我确定我做错了什么,但涉及.htaccess时我是n00b

all the URLs are in the same format, 14 in total: 所有网址都采用相同的格式,总共14个:

OLD:/laser-alignment-resources/presentations.cfm?pres=gas New: http://www.acquip.com/en/presentations/48-presentation-gas-turbine-thermal-alignment OLD:/laser-alignment-resources/presentations.cfm?pres = gas新: http ://www.acquip.com/en/presentations/48-presentation-gas-turbine-thermal-alignment

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

any help will be appreciated. 任何帮助将不胜感激。

Your question isn't clear on how you're trying to perform the redirects in your .htaccess file, so for next time I'd recommend that you post some samples of the code that you've tried so that we can help you more easily. 您对如何尝试在.htaccess文件中执行重定向的问题不清楚,因此,下次我建议您发布一些尝试过的代码示例,以便我们为您提供更多帮助容易。

Based on your Apache tag and the problem you're describing, I'm going to assume that you were using mod_alias though, trying to do something like this: 根据您的Apache标记和您描述的问题,我将假设您正在使用mod_alias ,并尝试执行以下操作:

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

This doesn't work though, as the Redirect directive seems to only examine the path portion of the request, and not the query string. 但是这不起作用,因为Redirect指令似乎仅检查请求的路径部分,而不检查查询字符串。

If you have mod_rewrite available, you can setup rewrite rules for the URLs that you need to redirect based on their query strings. 如果有可用的mod_rewrite ,则可以根据其查询字符串为需要重定向的URL设置重写规则。 This would look something like this: 看起来像这样:

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]

...and so on. ...等等。 You can keep your currently working Redirect statements, as they should work fine side-by-side with these rules. 您可以保留当前工作的Redirect语句,因为它们可以与这些规则并排使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM