如何通过使用Apache中的redirectmap来使用查询字符串重定向源URL [英] How to redirect source URL with query string by using redirectmap in Apache

查看:55
本文介绍了如何通过使用Apache中的redirectmap来使用查询字符串重定向源URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将旧站点URL(以.aspx/asp结尾,并且有数百个)迁移到新站点(以.jsp/servlets结尾). 我们选择使用RedirectMapRedirectRule在Apache中实现此迁移.普通的URLS正常工作.但是源URL中的区分大小写会导致重定向到PAGENOTFOUND(例如,/magazine/Magazine.aspx?Id=4 重定向到PAGENOTFOUND而不是 http://mydomain.com/advice/beauty).

I need to migrate my old site URLs (ending with .aspx/asp and these are a few hundreds) to new site (ending with .jsp/servlets). We've opted to use RedirectMap and RedirectRule to implement this migration in Apache. The plain URLS are working fine. But case-sensitivity in the source URL is causing redirecting to a PAGENOTFOUND (For example, /magazine/Magazine.aspx?Id=4 is redirecting to PAGENOTFOUND instead of http://mydomain.com/advice/beauty).

另一个问题是,它无法使用查询字符串重定向源URL(例如,/Help/Help.aspx?HelpID=6 重定向到PAGENOTFOUND而不是 http://mydomain.com/services/essential-info ).

Another issue is that it is unable to redirect the the source URLs with a query string (for example, /Help/Help.aspx?HelpID=6 is redirecting to PAGENOTFOUND instead of http://mydomain.com/services/essential-info).

请在下面找到示例重定向地图文本文件.

Please find sample redirectmap text file below.

/100001/Product.aspx    http://mydomain.com/urlredirect/p100003
/100002/Product.aspx    http://mydomain.com/urlredirect/p100005
/Help/Help.aspx?HelpID=6    http://mydomain.com/services/essential-info
/Help/Help.aspx?HelpID=11   http://mydomain.com/services/info-about-delivery-methods
/Magazine/Feature.asp?Id=816    http://mydomain.com/advice/all-about-you.asp
/Magazine/Magazine.aspx?Id=4    http://mydomain.com/advice/beauty
/Advive/all-about-you.asp   http://mydomain.com/advice/beauty-in-you

使用Apache编写的重定向代码

Redirect code written in Apache

RewriteEngine on
RewriteMap text2id txt:/opt/webserver/apache/conf/redirectmap.txt
RewriteRule ^(.*\.(aspx|asp)) ${text2id:$1} [NC,R=301,L]

推荐答案

林俊(Jon Lin)的回答帮助我在地图上搜索了正确的重定向.我们已经更新了以下代码.

Jon Lin's answer helped me to search for the correct redirect in the map. We've updated the code as below.

下面是实现的重定向代码.

Below is the redirect code implemented.

RewriteEngine on
RewriteMap text2id txt:/opt/webserver/apache/conf/redirectmap.txt
# Base URL Does have a QS 
RewriteCond %{REQUEST_URI} ^(.*\.(aspx|asp).*)
RewriteCond ${text2id:%1?%{QUERY_STRING}} ^(.*\?.*)$
RewriteRule ^.*$ %1 [R=301,L]

# Base URL exists in the map
RewriteCond %{REQUEST_URI} ^(.*\.(aspx|asp).*)
RewriteRule ^.*$ ${text2id:%1|PAGENOTFOUND} [R=301,L]

这篇关于如何通过使用Apache中的redirectmap来使用查询字符串重定向源URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆