6

quick question -

Currently my urls look like this: index.cfm/camp/another-test

I would like for them to look like this: camp/another-test

I'm able to do this fine on apache with my .htaccess but I need to be able to do it on iis7 with the web.config. Here's my rewrite so far:

<rewrite>
  <rules>
    <rule name="Remove index.cfm" enabled="true">
      <match url="^(.*)$" ignoreCase="true" />
      <conditions logicalGrouping="MatchAll">
        <add input="{SCRIPT_NAME}" negate="true" pattern="^/(assets|files|miscellaneous|robots.txt|favicon.ico|sitemap.xml|index.cfm)($|/.*$)" />
      </conditions>
     <action type="Rewrite" url="/index.cfm/{R:1}" />
    </rule>
  </rules>
</rewrite>

Thanks for the help!

dspz
  • 61
  • 2

2 Answers2

1

I believe CFWheels requires that you route rewrite requests through rewrite.cfm not index.cfm.

See the comment by Chris Peters on this question

If you adjust:

<rewrite>
  <rules>
    <rule name="Remove index.cfm" enabled="true">
      <match url="^(.*)$" ignoreCase="true" />
      <conditions logicalGrouping="MatchAll">
        <add input="{SCRIPT_NAME}" negate="true" pattern="^/(assets|files|miscellaneous|robots.txt|favicon.ico|sitemap.xml|index.cfm)($|/.*$)" />
      </conditions>
      <action type="Rewrite" url="/index.cfm/{R:1}" />
    </rule>
  </rules>
</rewrite>

to:

<rewrite>
  <rules>
    <rule name="ColdFusion on Wheels URL Rewriting" enabled="true">
      <match url="^(.*)$" ignoreCase="true" />
      <conditions logicalGrouping="MatchAll">
        <add input="{SCRIPT_NAME}" matchType="Pattern" ignoreCase="true" negate="true" pattern="^/(flex2gateway|jrunscripts|cfide|CFFileServlet|cfformgateway|railo-context|files|images|javascripts|miscellaneous|stylesheets|robots.txt|favicon.ico|sitemap.xml|rewrite.cfm)($|/.*$)" />
      </conditions>
      <action type="Rewrite" url="/rewrite.cfm/{R:1}" />
    </rule>
  </rules>
</rewrite>

it should solve your problem, provided you have:

<cfset set(URLRewriting = "On")>

within /config/settings.cfm

Community
  • 1
  • 1
Avery Martell
  • 317
  • 1
  • 7
  • Yeah, I had looked at the index and rewrite and mistakenly assumed they were the same, but after looking at the question I see Wheels handles the requests differently. I changed it to use rewrite.cfm but it still only works if the url is /rewrite.cfm/camp/test. And I have urlRewriting on, which controls the format of the generated linkTo urls. Thanks for the info though! – dspz Nov 26 '13 at 21:04
  • @dspz what version of IIS are you using? – Avery Martell Nov 26 '13 at 21:29
  • I'm using iis7, rewrite module 2.0. I know the rewriting is active, it's just not doing what I want. – dspz Nov 26 '13 at 21:37
  • @dspz Okay, bear with me here. I happened to have an IIS7 development server with a CFWheels app which was experiencing the exact same behavior you're explaining. I edited my above post to reflect changes I made that got things working. I added matchType="Patten" and ignoreCase="true" to the condition and that got the rewrite working for me. Let me know how you make out. – Avery Martell Nov 26 '13 at 21:55
  • Tried that, unfortunately no luck. I did uncover a few more details, though. I'm using the ColdRoute plugin and it seems that with this web.config it's defaulting to the root route. When I access /camp/test it's just showing the index page, no errors. I dumped params and it's showing root as the route no matter what the url is. – dspz Nov 26 '13 at 22:12
  • @dspz Sorry, I don't have any experience with ColdRoute. I installed the plugin and gave it a try and a request to the default page was broken, but I was still able to access other pages such such as /camp/test properly. – Avery Martell Nov 26 '13 at 23:01
  • Make sure you add to your settings file. – osekmedia Mar 18 '14 at 22:53
  • I'm having issues. With rewrite on and everything, I can go to /rewrite.cfm and /index.cfm with no errors. However if I remove them, I get a 404 from Jetty (not IIS) saying /rewrite.cfm/ is not found. Notice the `/` at the end there. I feel that is what is causing this. – Leeish Dec 30 '14 at 22:28
  • Additionally, with web.config rules disabled, I can go to index.cfm/controller/action and it works however rewrite.cfm/controller/action gives me a 404 from Jetty. It's like something about Railo doesn't like using the rewrite.cfm instead of the inedex.cfm. I've noticed when I go to the webadmin as well, it won't negate the rewrite rule. – Leeish Dec 30 '14 at 22:48
-1

Try adding this rewriting rule:

    <rewrite>
      <rules>
        <rule name="ColdFusion on Wheels URL Rewriting" enabled="true">
          <match url="^(.*)$" ignoreCase="true" />
          <conditions logicalGrouping="MatchAll">
            <add input="{SCRIPT_NAME}" negate="true" pattern="^/(flex2gateway|jrunscripts|cfide|CFFileServlet|cfformgateway|railo-context|files|images|javascripts|miscellaneous|newsletters|stylesheets|robots.txt|favicon.ico|sitemap.xml|rewrite.cfm)($|/.*$)" />
          </conditions>
          <action type="Rewrite" url="/rewrite.cfm/{R:1}" />
        </rule>
      </rules>
    </rewrite>
Anurag
  • 1,018
  • 1
  • 14
  • 36