Mod_Rewrite w Apache mod_jrun22.so & ColdFusion 9 on cPanel

Posted by Eddie B on Server Fault See other posts from Server Fault or by Eddie B
Published on 2012-06-25T22:03:09Z Indexed on 2012/06/28 9:17 UTC
Read the original article Hit count: 220

Filed under:
|
|

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>

© Server Fault or respective owner

Related posts about apache2

Related posts about mod-rewrite