4

我正在使用 301 重定向修复我的所有 URL 以缩短它们。我已经修复了几乎所有这些,但是有一个以 .cfm 结尾的 url 不会重写。

FROM: http://www.mydomain.com/index.cfm/catlink/17/pagelink/7/sublink/34/art/41/rec/1/page.cfm

TO: http://www.mydomain.com/story/resources/health/page/168/page.html

如果我更改/page.cfm为,/page.html则重写将起作用。

这是适用于我的其他网址的重写规则

RewriteRule ^index.cfm/catlink/([a-zA-Z0-9/-]+)([/])pagelink/([a-zA-Z0-9/-]+)([/])sublink/([a-zA-Z0-9/-]+)([/])art/([a-zA-Z0-9/-]+)(.*)$ 

http://localhost/index.cfm?page=moved&cat=$3&subcat=$5&article=$7&story=$8 [R=301]

为什么当 URL 以 .html 结尾但以 .cfm 结尾时它不起作用?我究竟做错了什么?

这是当前链接,将不起作用:

http://www.mydomain.com/index.cfm/catlink/17/pagelink/7/sublink/34/art/41/rec/1/page.cfm

如果我手动将它的结尾更改为 .html,我可以让它工作:

http://www.mydomain.com/index.cfm/catlink/17/pagelink/7/sublink/34/art/41/rec/1/page.html
4

2 回答 2

2

The issue is that Apache httpd is passing it off to Tomcat before Apache looks at the .htaccess. To test this, move your rewrite rules into your vhost. If they work, then that's what the problem was.

于 2011-11-21T18:35:46.137 回答
0

首先,将 RewriteRule 的第一部分更改为以下更简洁的表达式:

^index.cfm/catlink/(\d+)/pagelink/(\d+)/sublink/(\d+)/art/(\d+)/(.*)$

我相信仅此一项就可以解决问题。但是,如果没有,并且您不关心URL 的其余部分,请尝试以下操作:

^index.cfm/catlink/(\d+)/pagelink/(\d+)/sublink/(\d+)/art/(\d+)/

注意:这会删除锚 ( $),因此允许 URL 以开放式结尾。

于 2011-10-31T14:19:29.520 回答