htaccess rewrite rules are not working with urls that end with .cfm

为君一笑 提交于 2019-12-10 15:18:51

问题


I'm working on fixing all my URL's to be shorter with 301 redirects. I have fix almost all of them, however there is a url that is ending with .cfm that will not rewrite.

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

If I change /page.cfm to /page.html then the rewrite will work.

Here is the rewrite rule that works for my other urls

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]

Why does it work when the URL ends with .html but not when it ends with .cfm? What am I doing wrong?

This is current link and will not work:

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

If I manually change the end of it to .html, I can get it to work:

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

回答1:


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.




回答2:


First off, change your the first part of your RewriteRule to be the following, more concise expression:

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

I believe that alone might resolve the issue. However, if it does not, and you don't care about the rest of the URL, try the following:

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

Note: this removes the anchor ($) and therefore allows the URL to be open ended.



来源:https://stackoverflow.com/questions/7949746/htaccess-rewrite-rules-are-not-working-with-urls-that-end-with-cfm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!