coldfusion htaccess rewrite rule generating error

I'm using isapi rewrite

my rewrites work but i'm trying to get rid of file extensions so instead of:

http://ikonltd.com/artists/ipad-artist/Abakanowicz.cfm

i can do

http://ikonltd.com/artists/ipad-artist/Abakanowicz

i found this in the isapi docs:

#Redirect extension requests to avoid duplicate content
RewriteRule ^([^?]+)\.cfm$ $1 [NC,R=301,L]

#Internally add extensions to request
RewriteCond %{REQUEST_FILENAME}.cfm -f
RewriteRule (.*) $1.cfm

but when i try to access:

http://ikonltd.com/artists/ipad-artist/Abakanowicz

i get this error:

Could not find the included template http://ikonltd.com/includes/header.cfm.
Note: If you wish to use an absolute template path (for example, template="/mypath/index.cfm") with CFINCLUDE, you must create a mapping for the path using the ColdFusion Administrator. Or, you can use per-application settings to specify mappings specific to this application by specifying a mappings struct to THIS.mappings in Application.cfc.
Using relative paths (for example, template="index.cfm" or template="../index.cfm") does not require the creation of any special mappings. It is therefore recommended that you use relative paths with CFINCLUDE whenever possible.

i've tried to include a mapping in my Application.cfm file and add it to my include/header.cfm path but i get the same error

my mapping:
<cfset this.mappings['myMapping'] = "D:\user\www\newsite\" />

this is what i have in my include:

<cfinclude template="/#this.mappings['myMapping']#/includes/header.cfm" />

this isn't working either
phillystyle123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

duncancummingCommented:
So without the htaccess, the header.cfm file gets included ok?  Strange.

I've never used that this.mappings struct before.  Why can't you just use a relative filepath in your cfinclude?
dgrafxCommented:
you can't include a template using "<cfinclude template="http://ikonltd.com/includes/header.cfm">" syntax!
it MUST be like "/includes/header.cfm".
I imagine you know that and its isapi that is causing this syntax error - is that correct?

I am not a guru in isapi rewrite but I do use it for a few sites and am moderately familiar.
Have you seen others using it in the fashion you are trying to use it?
Meaning is it a good idea to do what you are wanting to do??? And is it feasible.
I don't know - that might be a question you should ask!

Why are you wanting to do this?

If all you want to do is give the illusion of being at Abakanowicz instead of Abakanowicz.cfm then can you not use a 404 page methodology?
phillystyle123Author Commented:
Client requested leaving the file extension off.

this is how i'm calling the include:

<cfinclude template="/includes/header.cfm">

there must be a way to make this work:

#Redirect extension requests to avoid duplicate content
RewriteRule ^([^?]+)\.cfm$ $1 [NC,R=301,L]

#Internally add extensions to request
RewriteCond %{REQUEST_FILENAME}.cfm -f
RewriteRule (.*) $1.cfm

I'm going to test it w/o the includes
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

dgrafxCommented:
just because client wanted to do this doesn't mean that it's feasible ...
and like I said - why not 404?
phillystyle123Author Commented:
ah -
looking at the error it says:

The error occurred in D:\user\www\newsite\errors\pagenotfound.cfm: line 4

which means that something's wrong with my RewriteRule
duncancummingCommented:
The .htaccess stuff is a red herring here.  The problem is your use of an absolute path in the cfinclude.  My understanding is that if one .cfm file cfincludes another .cfm file, that second one won't be processed through the webserver a second time (i.e. it doesn't go anywhere near the .htaccess).

I'm repeating myself here, but, did this work prior to the .htaccess changes to handle the no .cfm extension?  Or, take out the .htaccess and it'll still fail for the same reasons, I expect.

This is from the documentation on the cfinclude tag:
ColdFusion searches for included files in the following locations:

   1. In the directory of the current page or a directory relative to the current page
   2. In directories mapped in the ColdFusion Administrator

You cannot specify an absolute URL or file system path for the file to include. You can only use paths relative to the directory of the including page or a directory that is registered in the ColdFusion Administrator Mappings. The following cfinclude statements work, assuming that the myinclude.cfm file exists in the specified directory:

<cfinclude template="myinclude.cfm">
<cfinclude template="../myinclude.cfm">
<cfinclude template="/CFIDE/debug/myinclude.cfm">


In that last example, the CFIDE is a mapping setup in the CF Administrator.  It may be you need to do the same for your /includes/ directory.
phillystyle123Author Commented:
http://ikonltd.com/artists/ipad-artist/Abakanowicz.cfm

using this for all includes:

<cfinclude template="/includes/header.cfm">

http://ikonltd.com/artists/ipad-artist/Abakanowicz - redirects to page not found.


duncancummingCommented:
If I go here, it's NOTHING to do with a redirect, and everything to do with the cfinclude using an absolute path:

http://ikonltd.com/artists/ipad-artist/Abakanowicz

The error I see (my highlight for emphasis):

Could not find the included template http://ikonltd.com/includes/header.cfm.
Note: If you wish to use an absolute template path (for example, template="/mypath/index.cfm") with CFINCLUDE, you must create a mapping for the path using the ColdFusion Administrator. Or, you can use per-application settings to specify mappings specific to this application by specifying a mappings struct to THIS.mappings in Application.cfc.
Using relative paths (for example, template="index.cfm" or template="../index.cfm") does not require the creation of any special mappings. It is therefore recommended that you use relative paths with CFINCLUDE whenever possible.
 
The error occurred in D:\gregikon\www\newsite\errors\pagenotfound.cfm: line 4

3 :
4 : <cfinclude template="http://ikonltd.com/includes/header.cfm">
duncancummingCommented:
So in summary, go to your CF Administrator, Mappings page.  Setup a new mapping for 'includes' that points to "D:\user\www\newsite\includes\" (or wherever your includes directory is).  The code should then work without any further modifications required.
phillystyle123Author Commented:
i don't have access to the cf admin. i can do it in application.cfm, no? not sure how though.

also, the code for the include <cfinclude template="/includes/header.cfm"> already works

it seems to me that it's the redirect that's faulty - i'm being redirected to pagenotfound.cfm when i'm trying to pull this url up:

http://ikonltd.com/artists/ipad-artist/Abakanowicz

this:

Could not find the included template http://ikonltd.com/includes/header.cfm.

is referring to this page:

pagenotfound.cfm

not this page:

http://ikonltd.com/artists/ipad-artist/Abakanowicz





duncancummingCommented:
There's two things happening here.  Firstly I'm guessing that the Abakanowicz.cfm file doesn't refer to the header.cfm include?  So, there's a mistake in your .htaccess, that is then going to your 404 page, pagenotfound.cfm.  That file refers to header.cfm, which is where the error due to the absolute url kicks in.

This blog post gives a good explanation of how to use the this.mappings structure.


So I think this is what you would need in your application.cfm / .cfc:
<cfset this.mappings['/includes']= "D:\user\www\newsite\includes">

Open in new window


And then refer to it like this in your pagenotfound.cfm:
<cfinclude template="/includes/header.cfm">

Open in new window


And all this is just to fix the error in your pagenotfound.cfm.  I need to give more thought to the .htaccess problem!
dgrafxCommented:
ONCE AGAIN - are you sure any of this is feasible - do you know of anyone else who has removed file extensions with a url rewrite?
AND why not use the 404 method most everyone uses? (just ask if you don't know)
phillystyle123Author Commented:
djrafx -

check out "Hide file extensions" on this page - this is what i'm trying to accomplish:

http://www.helicontech.com/isapi_rewrite/doc/examples.htm

why would i use the 404 method? isn't that a custom error page?

dgrafxCommented:
do you remember what I said in the other post about a newbie looking at something they don't understand and saying that's not gonna work
phillystyle123Author Commented:
djrafx -

appreciate the help, but please, spare me the patronizing. i'll try anything if it makes sense to try it.  

truth be told, i don't build much in cf, but i've been doing this for years so i know if something's worth trying or if it's going down a wrong path.

regarding your last comments:

1. "ONCE AGAIN - are you sure any of this is feasible - do you know of anyone else who has removed file extensions with a url rewrite?"

Yes, I'm sure it's feasible  -
check out "Hide file extensions" on this page - this is what i'm trying to accomplish:
http://www.helicontech.com/isapi_rewrite/doc/examples.htm

2. "AND why not use the 404 method most everyone uses? (just ask if you don't know)"
again, that's not what i'm trying to accomplish - i don't care about a custom error page right now - just trying to get my extensionless url to work




 i haven't tried your last bit of code in the question you're referencing because i'm jumping around between projects.  

dgrafxCommented:
apparently you think by 404 method that I'm talking about a custom error page???

I am not trying to be rude - sometimes yes I patronize - sorry - BUT I don't believe you have the experience to determine if something is worth trying or going down a wrong path.
I'm just trying to help you and now this is the 2nd question where you dont understand my responses, but say anyway that its headed down the wrong path.

I will look at your link and post in the morning - US Eastern time.
phillystyle123Author Commented:
"BUT I don't believe you have the experience to determine if something is worth trying or going down a wrong path."

as far as i can see, it's not cf -it's htaccess


dgrafxCommented:
the problem you are experiencing NOW of course is htaccess - because thats what you are using!
phillystyle123Author Commented:
your the man dgrafx - let me know if you come by any possible solutions
dgrafxCommented:
now whos being condescending ...

could you post your entire .htaccess file please
dgrafxCommented:
real quick - try REQUEST_URI instead of REQUEST_FILENAME
phillystyle123Author Commented:
yeah but i left you an opening by misspelling "your"

RewriteEngine on
RewriteBase /newsite/
#Redirect extension requests to avoid duplicate content
RewriteRule ^([^?]+)\.cfm$ $1 [NC,R=301,L]
#Internally add extensions to request
RewriteCond %{REQUEST_FILENAME}.cfm -f
RewriteRule (.*) $1.cfm
RewriteRule ^/newaq/popup/(.+?)/(.+?)\.cfm /newaq/popup.cfm?AutoArtID=$1&PageNum_newaqimages=$2 [QSA]
RewriteRule ^/newaq/popup-nw/(.+?)/(.+?)\.cfm /newaq/popup-nw.cfm?LastName=$1&AutoArtID=$2 [QSA]
RewriteRule ^/newaq/ipad-detail/(.+?)/(.+?)\.cfm /newaq/ipad-detail.cfm?permalink=$1&AutoArtID=$2 [QSA]
RewriteRule ^/artists/ipad-artist/(.+?)\.cfm /artists/ipad-artist.cfm?permalink=$1 [QSA]
RewriteRule ^/artists/ipad-exhibitions/(.+?)\.cfm /artists/ipad-exhibitions.cfm?permalink=$1 [QSA]
RewriteRule ^/artists/ipad-detail/(.+?)/(.+?)\.cfm /artists/ipad-detail.cfm?permalink=$1&AutoArtID=$2 [QSA]
RewriteRule ^/past/ipad-exhibitions/(.+?)\.cfm /past/ipad-exhibitions.cfm?ExID=$1 [QSA]
RewriteRule ^/past/ipad-detail/(.+?)/(.+?)\.cfm /past/ipad-detail.cfm?AutoArtID=$1&ExID=$2 [QSA]
RewriteRule ^/current/ipad-detail/(.+?)/(.+?)\.cfm /current/ipad-detail.cfm?AutoArtID=$1&ExID=$2 [QSA]
RewriteRule ^/newaq/newacq_detail/(.+?)/(.+?)/(.+?)\.cfm /newaq/newacq_detail.cfm?AutoArtID=$1&ArtistID=$2&PageNum_newaqimages=$3 [QSA]
dgrafxCommented:
thanks
did you try REQUEST_URI instead of REQUEST_FILENAME?
also - if that doesn't work temporarily remove everything after RewriteRule (.*) $1.cfm
also try removing rewritebase /newsite/
dgrafxCommented:
WORKING TESTED CODE AS FOLLOWS

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.cfm -f
RewriteRule ^(.*)$ $1.cfm

AND like i said - test this WITHOUT all the extra $%&%*@# you have in your file.
use JUST this code

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
phillystyle123Author Commented:
thanks dgrafx - this works great by itself but not with any of my rewrites. any idea how to implement both?
dgrafxCommented:
no idea ???
where did you get that stuff anyway?
don't answer that ...
no - is the answer
dgrafxCommented:
is there anything else on this question?
time to wrap up some of your questions ...
phillystyle123Author Commented:
this works by itself:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.cfm -f
RewriteRule ^(.*)$ $1.cfm

it needs to work with this as well though -currently i get redirected to pagenotfound

RewriteEngine on
RewriteBase /newsite/
RewriteRule ^/newaq/popup/(.+?)/(.+?)\.cfm /newaq/popup.cfm?AutoArtID=$1&PageNum_newaqimages=$2 [QSA]
RewriteRule ^/newaq/popup-nw/(.+?)/(.+?)\.cfm /newaq/popup-nw.cfm?LastName=$1&AutoArtID=$2 [QSA]
RewriteRule ^/newaq/ipad-detail/(.+?)/(.+?)\.cfm /newaq/ipad-detail.cfm?permalink=$1&AutoArtID=$2 [QSA]
RewriteRule ^/artists/ipad-artist/(.+?)\.cfm /artists/ipad-artist.cfm?permalink=$1 [QSA]
RewriteRule ^/artists/ipad-exhibitions/(.+?)\.cfm /artists/ipad-exhibitions.cfm?permalink=$1 [QSA]
RewriteRule ^/artists/ipad-detail/(.+?)/(.+?)\.cfm /artists/ipad-detail.cfm?permalink=$1&AutoArtID=$2 [QSA]
RewriteRule ^/past/ipad-exhibitions/(.+?)\.cfm /past/ipad-exhibitions.cfm?ExID=$1 [QSA]
RewriteRule ^/past/ipad-detail/(.+?)/(.+?)\.cfm /past/ipad-detail.cfm?AutoArtID=$1&ExID=$2 [QSA]
RewriteRule ^/current/ipad-detail/(.+?)/(.+?)\.cfm /current/ipad-detail.cfm?AutoArtID=$1&ExID=$2 [QSA]
RewriteRule ^/newaq/newacq_detail/(.+?)/(.+?)/(.+?)\.cfm /newaq/newacq_detail.cfm?AutoArtID=$1&ArtistID=$2&PageNum_newaqimages=$3 [QSA]
dgrafxCommented:
and how does all that have to do with your original question?

it's EXACTLY like the other question!
you ask a question and get some answers ...
then you post some more of the question which may actually change the question entirely!
you realize that certain types of answers create some work on our part dont you?
it's not like asking what 2+2 equals
one needs to sometimes setup a test environment and experiment just to give a rudimentary answer.

you are making it next to impossible for me to post in any future question of yours!

and as far as this question goes - what makes you think all the additional lines you added in are compatible?
phillystyle123Author Commented:
just a note - i inadvertently selected the wrong answer-i've requested that it be fixed

Automated Request for Attention: Q_26705257
dgrafxCommented:
thank you and good luck ...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.