简体   繁体   中英

convert web.config rewrite rule to htaccess rewrite rule (All files without an extension to be processed as .cfm)

I am moving a site from IIS 7 to Apache 2.4 and have the following web.config rewrite rule I am having trouble converting to .htaccess. The rule essentially allows for clean (seo friendly) urls by rewriting all files without an extension with the .cfm extension (eg www.mydomain/bag rewrites on the server as www.mydomain.com/bag.cfm. The working rule in web.config is shown below

<rule name="Rewrite all non extension requests to .cfm" stopProcessing="true">
      <match url="^(.*)$" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        <add input="{REQUEST_FILENAME}.cfm" matchType="IsFile" ignoreCase="false" />
      </conditions>
      <action type="Rewrite" url="{R:1}.cfm" />
    </rule>

I have tried all the like posts I could find on here and unfortunately none of them worked for me. I am running Lucee 5.0 on CentOS 7 (Apache 2.4) if that matters. Any guidance would be greatly appreciated.

I don't really know about Tomcat; I assume you need Apache because Tomcat's no good for serving your non-script content.

You could set them up so that they both have the same document root, thus have congruent URLs, but have Tomcat listening on a different port, and not have that port open externally. Then you could proxy requests that are for (hidden) cfm files like so:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.cfm -f
RewriteCond %{THE_REQUEST} ^\S++\s++([^?\s]++)(\?\S*)?
RewriteRule ^ http://127.0.0.1:8080%1.cfm%2 [NS,NE,P]
RewriteRule (?<=.cfm)$ http://127.0.0.1:8080/404.cfm [NS,NE,P]

The second rule is an example to pretend that the cfm files are not there if request directly.

You will need the appropriate proxy module(s) enabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM