Forum Moderators: phranque

Message Too Old, No Replies

Why can't I rewrite to an absolute path?

eg: /home/squatho5/public_html/assetMerger.php

         

CarBoffin

2:44 pm on Apr 7, 2008 (gmt 0)

10+ Year Member



I have a .htaccess file in "/home/squatho5/public_html/" with this:

Options -Indexes
AddDefaultCharset utf-8
RewriteEngine on
RewriteRule \.(js¦css)$ /home/squatho5/public_html/assetMerger.php?path=%{SCRIPT_FILENAME} [L]

I want it to affect all child directories (site directories) so a site here "/home/squatho5/public_html/mostplays.com/" would have the above rule apply (I use "RewriteOptions inherit").

I expect this to resolve to the absolute path as it starts with a "/", but I get an error like this:


[Mon Apr 7 09:13:07 2008] [error] [client 90.231.35.156] File does not exist: /home/squatho5/public_html/mostplays.com[4]/home/squatho5/public_html/assetMerger.php[/4]

Can anyone help?

jdMorgan

3:09 pm on Apr 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do not include the part of the path that is already specified as DocumentRoot in your rewriterule's substitution path. As you can see, doing so causes that path-part to be duplicated in the requested filepath.

Also, be aware that code in .htaccess cannot "reach" directories above the DocumentRoot. This is required for security. If you need to reach above DocumentRoot, then you'll have to put the code into httpd.conf at the server config level.

Jim

CarBoffin

3:30 pm on Apr 7, 2008 (gmt 0)

10+ Year Member



Thanks, I see why it's not working now.

Would it be possible for a shared server to have its httpd.conf edited so the rule only applied to sites in my username "/home/squatho5/"? or would a dedicated server be required?

jdMorgan

3:48 pm on Apr 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In almost all cases, you'll need a dedicated server of a VPS (Virtual Private Server) to get permission to edit httpd.conf. You can look at your "Control Panel" to see if it supports adding custom code to your configuration, but most shared hosts don't allow it because it can dramatically raise their support costs.

Jim