Removing index.cfm from url with web config
Asked Answered
A

2

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!

Anselmo answered 26/11, 2013 at 20:17 Comment(0)
C
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

Colorblind answered 26/11, 2013 at 20:53 Comment(9)
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!Anselmo
@Anselmo what version of IIS are you using?Colorblind
I'm using iis7, rewrite module 2.0. I know the rewriting is active, it's just not doing what I want.Anselmo
@Anselmo 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.Colorblind
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.Anselmo
@Anselmo 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.Colorblind
Make sure you add <cfset set(URLRewriting="On")> to your settings file.Antibiotic
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.Jackpot
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.Jackpot
B
-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>
Bainmarie answered 13/1, 2015 at 17:42 Comment(2)
This is exactly what the last person said a month before you.Cerebral
@coderpros but is this in-correct to deserve a downvote?Bainmarie

© 2022 - 2024 — McMap. All rights reserved.