Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can I utilize mod_rewrite at either the httpd.conf level or per-directory level when mod_jrun22 seems to have short-stopped the rewrite process for ColdFusion pages?

I have a ColdFusion 9 based site running on Centos 5.8 w cPanel. cPanel uses EasyApache 3 to manage virtual host containers and as such the conf for mod_jrun22.so, /usr/local/apache/conf/includes/pre_main_global.conf, is loaded prior to the main httpd.conf with the domain specific rules for the container.

My assertion is that .cfm pages are failing to be rewritten due to the mod_jk22.so module having priority in the directive chain. To note, I also have a WordPress blog in the site where the rewrites appear to be working fine. For example the following code to remove the index file works fine for php and fails with cfm ...

.htaccess under /blog/ : This works

Options -Indexes -Multiviews

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

.htaccess under / : This does not work as expected. Apache serves the page.

ASSERT: This would redirect to domain.com/ without index.cfm

Options -Indexes -Multiviews

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.cfm$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.cfm [L]
</IfModule>

.htaccess under / : This works

I'm presuming this is working because the redirect is to another .cfm page and a 404 handler in Application.cfc ...

Options -Indexes -Multiviews 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^.*\.cfm$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{ENV:REDIRECT_STATUS} =404
RewriteRule . /404.cfm$ [L]
</IfModule>

I've attempted numerous different methods to rewrite .cfm urls ... Adding [PT], [L], [R], [NS], Moving the script to Directory blocks under httpd.conf --- all with the same results ... either the rewrite doesn't work or Apache crashes in an endless loop ... Any help would be greatly appreciated.

Below is a single-visit rewrite log snippet for a request to /index.cfm ... the pass-through is taking effect before the rewrite ...

 cat rewrite_dump_mod | grep index.cfm

[perdir /home/foo/public_html/] strip per-dir prefix: /home/foo/public_html/index.cfm -> index.cfm
[perdir /home/foo/public_html/] applying pattern '^.*\.cfm$' to uri 'index.cfm'
[perdir /home/foo/public_html/] pass through /home/foo/public_html/index.cfm
[perdir /home/foo/public_html/] strip per-dir prefix: /home/foo/public_html/index.cfm -> index.cfm
[perdir /home/foo/public_html/] applying pattern '^.*\.cfm$' to uri 'index.cfm'
[perdir /home/foo/public_html/] pass through /home/foo/public_html/index.cfm

* UPDATE *

I've managed to figure this out ... it took a while ...

Options -Indexes -Multiviews +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index\.cfm
RewriteRule ^(.*)index.cfm http://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
share|improve this question
Can you clarify what you mean by This would redirect to the directory slash.? And give examples of what requests you're sending? Maybe also turn on a RewriteLog and set RewriteLogLevel 9. – Shane Madden Jun 26 '12 at 2:15
1  
You should really not use rewriterules in .htaccess files. One of the reason is that they only get called after the url to filename translation, so anything that causes a URL to be translated in to something that is not a file might result in your .htaccess file not being read at all. Try, ifat all possible, to have your rewrites in your server config, that gives them a chance to act earlier. – Krist van Besien Apr 15 at 7:59
@KristvanBesien Re: "URL not being read" :: Could you please provide a resource confirming that statement as this is the first time I've heard that. :-) – Eddie B Apr 17 at 13:15
@EddieB See the docs: httpd.apache.org/docs/2.2/howto/htaccess.html. From the docs it's clear that .htaccess files are only read after the file that is going to be used to serve the request has been determined. The docs also discuss at length while using .htaccess files is a bad idea in general. – Krist van Besien Apr 18 at 15:42
@KristvanBesien Please note I'm not disputing you're statement. However, I've read the docs at some length and do not see anything regarding the chain-of-custody for the request filename regarding per-dir config ... I do agree though about .htaccess --- generally I use the httpd.conf unless I'm working for a client that doesn't have root access ... – Eddie B Apr 18 at 21:50
show 1 more comment

migrated from stackoverflow.com Jun 25 '12 at 22:11

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.