Search code examples
coldfusionurl-rewritingcoldfusion-10

When using URL rewrite files are included multiple times?


I am developing a new site in ColdFusion 10 and doing some url rewriting using the .htaccess file. I have three rules that work very well when I call them without other includes. When I wrap them in includes, I get an error.

Here are my rules:

RewriteEngine on
RewriteRule ^advertise$ /index.cfm?Section=Advertise
RewriteRule ^bike/([0-9]+)/([0-9]+)/ /index.cfm?Section=Bike&BikeID=$1&FeatureID=$2
RewriteRule ^bike/([0-9]+)/ /index.cfm?Section=Bike&BikeID=$1

The index page figures our which section to show and calls includes the appropriate file wrapped around a header and footer, like this:

include "header.cfm"; 
include "#VARIABLES.Section#.cfm";
include "footer.cfm";

The problem is, it doesn't quite work for the "Bike" pages, the second two rules. It appears that the header file is included several times, which makes the links to the CSS and other files bad, which messes up the page. If I comment out the header and footer includes, everything works just fine, but there's no header or footer, which is not what I want.

// include "header.cfm"; 
include "#VARIABLES.Section#.cfm";
// include "footer.cfm";

Is there something in the url rewrite rules that causes the bike pages to be loaded several times and then fail?

http://flyingpiston2012-com.securec37.ezhostingserver.com/

You can try the page here and see the problem by clicking the links. Any ideas on how to fix this?

UPDATE

When I make all of my links absolute by including the entire URL, the problem goes away.

<cfoutput>
<link href="#APP.Home#/bootstrap/css/bootstrap.css" rel="stylesheet">
</cfoutput>

Still, I should NOT have to include an absolute path to files. Any hints as to why this isn't working for me?

UPDATE

// THIS FIXES THE PROBLEM
<base href="#APP.Home#/">
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">

// THIS FIXES THE PROBLEM
<link href="#APP.Home#/bootstrap/css/bootstrap.css" rel="stylesheet">

// THIS IS THE PROBLEM
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">

Solution

  • This could happen because you didn't tell Apache to stop parsing on match. Try to make rules look like this:

    RewriteRule ^advertise$ /index.cfm?Section=Advertise [L]
    RewriteRule ^bike/([0-9]+)/([0-9]+)/ /index.cfm?Section=Bike&BikeID=$1&FeatureID=$2 [L]
    RewriteRule ^bike/([0-9]+)/ /index.cfm?Section=Bike&BikeID=$1 [L]