I’m at my wits’ end… I’m trying to do something simple, yet I can’t understand what is going wrong…
I’m simply trying to take all requests to the domain, and route them to index.php
EDIT for clarity: index.php acts as a dispatcher for the request, as part of a framework.
I’ve got this working on my local machine without problems, but on the server (VPS Linux with Plesk) I’m having all sorts of problems…
EDIT for clarity: These rules are defined in the vhost.conf config file for the virtual host.
Here’s the mod_rewrite:
<IfModule rewrite_module>
RewriteEngine On
RewriteRule ^/.* /index.php
</IfModule>
Here’s the apache error log when I attempt to go to “www.mydomain.com/home/index” (for example):
[debug] core.c(3072): [client xxx.xxx.xxx.xxx] r->uri = /phppath/cgi_wrapper/phppath/cgi_wrapper/phppath/cgi_wrapper/home/index
[debug] core.c(3078): [client xxx.xxx.xxx.xxx] redirected from r->uri = /phppath/cgi_wrapper/phppath/cgi_wrapper/home/index
[debug] core.c(3078): [client xxx.xxx.xxx.xxx] redirected from r->uri = /phppath/cgi_wrapper/home/index
[debug] core.c(3078): [client xxx.xxx.xxx.xxx] redirected from r->uri = /home/index
As you can see from the trace, it seems to redirect the /home/index to /phppath/cgi_wrapper/ which then seems to get passed on again to /phppath/cgi_wrapper/phppath/cgi_wrapper/home/index, and so on until the maximum internal redirects is reached.
An HTTP 500 is sent to the browser.
Further EDIT – extra information. From what I can make out from the way Plesk scatters its files about, these are the only two lines which have an effect on the virtual host. I think it’s probably that Action statement… can I override it somehow in the vhost.conf?
in php-cgi.conf:
ScriptAlias /phppath/ "/var/www/cgi-bin/cgi_wrapper/"
Action php-script /phppath/cgi_wrapper
in php.conf:
AddHandler php5-script .php
Further EDIT: Found this within a dynamically generated conf file (at vhost level).
<Files ~ (.php)>
SetHandler None
AddHandler php-script .php
Options +ExecCGI
allow from all
</Files>
Has anyone got any ideas as to what’s happening? I’ve been pulling my hair our for two days… Thanks in advance
2
Answers
After much tearing of hair, and gnashing of teeth, and three keyboards later... I've managed to find something that works. It's not pretty, but it does the job... If anyone can offer any improvements on this, please do - I'm all ears. Or eyes. As it were.
So, I first noticed that recurring
/phppath/cgi_wrapper/home/index
problem in the Apache Log, which got me thinking: "Maybe I shouldn't be passing/home/index
to the PHP CGI, but I should be passingindex.php
". So, I modified the Rewrite as follows:I've simply added the PassThrough (PT) flag, which according to the documentation passes the rewrite result through to the handler.
This got me the following apache error_log:
which I considered an improvement, but it still wasn't working.
So then I went to my sparkly new rewrite_log to see if this could illuminate me. I saw:
So, from this I deduced that I was having the same problem:
/phppath/cgi_wrapper/index.php
was now being passed into the rewrite engine again to be rewritten, and this was coming out with/index.php
again, which was being passed back in, and etc. etc.So I added a condition. (This is the bit which seems ugly to me; I'm sure there's a better way):
That RewriteCond is basically saying: Apply the following rule if the request does NOT begin with
/phppath
.And that's it. Now it's working; all requests are being handled by index.php, as required.
Check if your server supports
mod_rewrite
in.htaccess
or you may have to writeweb.config
file with the following code