Htaccess rewrite rules do not work with URLs that end in .cfm

I am working on fixing my entire URL to be shorter with 301 redirects. I will fix almost all of them, however there is a URL that ends with .cfm that will not be rewritten.

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 rewriting will work.

Here is a 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 this work when the URL ends in .html, but not when it ends in .cfm? What am I doing wrong?

This is the 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 changed its end to .html, I can make it work:

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

The problem is that Apache httpd passes it to Tomcat before Apache looks at .htaccess. To test this, move your rewrite rules to your prize. If they work, then what is the problem.

+2
source

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

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

I believe that only this can solve the problem. However, if this is not the case, and you do not care about the rest of the URL, try the following:

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

Note. this removes the binding ( $ ) and therefore allows you to open the url.

0
source

All Articles