Forum Moderators: phranque
.php files on my server load perfectly when using the direct file path www.example.com/subdomain/test.php.
But when I try accessing it using a rewrite rule in my httpd file it says it cannot the file because its either unavailable or cannot be found.
I get the following in my rewrite log
init rewrite engine with requested uri /subdomain//index.html
applying pattern '^(.*)' to uri '/subdomain//index.html'
pass through /leeching//index.html
init rewrite engine with requested uri /subdomain//index.php
applying pattern '^(.*)' to uri '/subdomain//index.php'
pass through /leeching//index.php
Theres nothing in the error log. I think the problem lies with the double slash, but have not been able to get rid of it. When I use an external rewrite it works perfectly, only thing is I want an internal rewrite.
My Rewrite Code is:
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example.com(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3!^(.*)<>\1$ [NC]
RewriteRule ^(.*) /%1/$1 [NC,PT]
I'm hoping this is a silly small error on my behalf.
Yes, but an important one.
.htaccess is referred to as a "per-directory" context. Therefore, in .htaccess, the requested URL-path "seen" by mod_rewrite's RewriteRule when matching against patterns are stripped of the path to the local directory.
For example. if you request "example.com/foo/bar/quux/test.html," and your .htaccess file is in the /foo subdirectory, the requested local URL-path "seen" by RewriteRules in that file will be "bar/quux/test.html"
If located in the foo/bar/quux subdirectory, then the RewriteRule would "see" only "index.html".
Likewise, requested URL-paths for resources located in your top-level Web directory are stripped of their leading slashes.
In httpd.conf, the requested URL seen by RewriteRule is the entire requested URL path, because you are now at the very "top" of the path. So the pattern used to check URLs needs to include the leading slash:
RewriteRule [b]^/([/b].*) /%1/$1 [NC,PT]
Also, the purpose of the code that relies on advanced regex is to prevent looping in an .htaccess context. It is not needed if the code is in httpd.conf. A simplified and portable routine for httpd.conf would be:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com [NC]
RewriteRule ^/(.*) /%1/$1 [L]
I thought the problem lay with the mod rewrite, as only then did the browser try to download the .php files rather than parse them. I think that the problem may actually lie with the VirtualHost setup.
I've been googling and can't find anyone else with this problem. My php.conf are in a seperate file included at the top of my httpd file. They're working fine because normally php parses ok. I found this in my error log:
'mod_include: Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed,' so I added 'Options All'. Now the error log simply says 'Directory index forbidden by rule: /home/httpd/vhosts/domain.com/httpdocs/' whenever I type in an url with a .php. Although mod rewrite finds my .html files fine!
These are my VirtualHost configurations
<VirtualHost 111.111.111.1;80>
DocumentRoot /home/httpd/vhosts/domain.com/httpdocs
ServerName domain.com
ServerAlias domain.com
Options +FollowSymlinks
<Directory /home/httpd/vhosts/domain.com/httpdocs>
Options All
Order allow,deny
allow from all
</Directory>
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule ^/(.*) /%1/$1 [L]
</VirtualHost>
I've tried lots of different things and I'm hoping somebody may have come accross this same problem as I'm running out of options. I'm hoping its something small I've missed. This forum is excellent btw, I'm so impressed by the expertise and the high level of expertise.
Em
My virtual host configurations are:
<VirtualHost 000.000.000.0:80>
DocumentRoot /home/httpd/vhosts/domain.com/httpdocs
ServerName domain.com
ServerAlias domain.com
Options +FollowSymlinks
<Directory /home/httpd/vhosts/domain.com/httpdocs>
Order allow,deny
allow from all
AllowOverride All
</Directory>
</VirtualHost>
If I add *.domain.com to the ServerAlias it attempts to download the .php files at www.domain.com as well.
Is there a php safe mode or something that I have to turn off to avoid this. Thanks again for your suggestions!
[edited by: jdMorgan at 3:12 am (utc) on Aug. 18, 2005]
[edit reason] Obscured specifics. [/edit]
I've listed the steps here on how to create subdomains to subdirectorys on the fly, incase anybody else is struggling with Plesk.
Create file vhost.conf at home/httpd/vhosts/example.com/conf/vhost.conf
Insert the following code:
<IfModule mod_rewrite.c>
ServerAlias *.example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^(www¦admin¦control\.) [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com [NC]
RewriteRule ^/(.*) /%1/$1 [L]
</IfModule>
Run the following:
/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=example.com
Restart with command shutdown -r now