【发布时间】:2012-07-17 16:32:30
【问题描述】:
因为我很幸运地设法让查询字符串正确重定向,之前只传递查询字符串参数,并且整个网站和 webmasterworld 中关于查询字符串重定向的总体建议似乎是“将其作为 RewriteCond 查询字符串处理”,我正在尝试对一组大约 10 个 URL 使用以下类型规则。
示例网址:
http://www.example.org/training_book.asp?sInstance=1&EventID=139
到目前为止我所拥有的:
RewriteCond %{QUERY_STRING} ^training_book.asp\?sInstance=1&EventID=139
RewriteRule /clean-landing-url/ [NC,R=301,L]
所以,我想要发生的是
http://www.site.org/training_book.asp?sInstance=1&EventID=139 301> http://www.site.org/clean-landing-url
但是发生的事情是这样的:
http://www.site.org/training_book.asp?sInstance=1&EventID=139 301> http://www.site.org/training_book.asp/?sInstance=1&EventID=139
它在查询字符串之前添加一个正斜杠,然后解析完整的 URL(显然是 404ing。)
我错过了什么?实际 %{QUERY_STRING} 参数是否存在正则表达式问题?
提前致谢!
编辑-
这是我到目前为止的位置。
根据下面@TerryE 的建议,我尝试实施以下规则。
我有一组带有以下参数的网址:
http://www.example.org/training_book.asp?sInstance=1&EventID=139
http://www.example.org/training_book.asp?sInstance=2&EventID=256
http://www.example.org/training_book.asp?sInstance=5&EventID=188
等等
需要重定向到的地方
http://www.example.org/en/clean-landing-url-one
http://www.example.org/en/clean-landing-url-two
http://www.example.org/en/clean-landing-url-three
等等
这是我目前拥有的 htaccess 文件的确切结构,包括目前运行良好的“简单”重定向的完整示例(注意 - http://example.com > http://www.example.com 重定向在 httpd.conf 中强制执行)
#301 match top level pages
RewriteCond %{HTTP_HOST} ^example\.org [NC]
RewriteRule ^/faq.asp /en/faqs/ [NC,R=301,L]
此块中的所有 URL 都属于这种类型。所有这些 URL 都可以完美运行。
#Redirect all old dead PDF links to English homepage.
RewriteRule ^/AR08-09.pdf /en/ [NC,R=301,L]
此块中的所有 URL 都属于这种类型。所有这些 URL 都可以完美运行。
问题出在这里:我仍然无法将以下类型的 URL 重定向。根据@TerryE 的建议,我尝试如下更改语法。下面的块不能正常工作。
#301 event course pages
RewriteCond %{QUERY_STRING} sInstance=1EventID=139$
RewriteRule ^training_book\.asp$ /en/clean-landing-url-one? [NC,R=301,L]
这个的输出是
http://staging.example.org/training_book.asp/?sInstance=1&EventID=139
(目前适用于staging.example.org,将适用于example.org)
(我已经“隐藏”了一些实际语法,方法是在最初的问题中将它从 training_book 更改为 event_book,但我已将其改回尽可能真实。)
【问题讨论】:
标签: regex apache .htaccess mod-rewrite redirect