skip to Main Content

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


  1. Chosen as BEST ANSWER

    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 passing index.php". So, I modified the Rewrite as follows:

    <IfModule rewrite_module>
        RewriteEngine On
        RewriteLog /blah/blah/blah/rewrite_log
        RewriteLogLevel 5
    
        RewriteRule ^.*$ /index.php [PT]
    </IfModule>
    

    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:

    [debug] core.c(3078): [client xxx.xxx.xxx.xxx] redirected from r->uri = /index.php
    [debug] core.c(3078): [client xxx.xxx.xxx.xxx] redirected from r->uri = /index.php
    [debug] core.c(3078): [client xxx.xxx.xxx.xxx] redirected from r->uri = /index.php
    

    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:

    xxx.xxx.xxx.xxx - - [28/Aug/2012:15:38:05 +0400] [www.mydomain.com/sid#7f3c39001360][rid#7f3c390bbc88/initial] (2) rewrite '/' -> '/index.php'
    xxx.xxx.xxx.xxx - - [28/Aug/2012:15:38:05 +0400] [www.mydomain.com/sid#7f3c39001360][rid#7f3c390bbc88/initial] (2) forcing '/index.php' to get passed through to next API URI-to-filename handler
    xxx.xxx.xxx.xxx - - [28/Aug/2012:15:38:05 +0400] [www.mydomain.com/sid#7f3c39001360][rid#7f3c390c2710/initial/redir#1] (2) init rewrite engine with requested uri /phppath/cgi_wrapper/index.php
    xxx.xxx.xxx.xxx - - [28/Aug/2012:15:38:05 +0400] [www.mydomain.com/sid#7f3c39001360][rid#7f3c390c2710/initial/redir#1] (3) applying pattern '^/(.*)$' to uri '/phppath/cgi_wrapper/index.php'
    

    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):

    <IfModule rewrite_module>
        RewriteEngine On
        RewriteLog /blah/blah/blah/rewrite_log
        RewriteLogLevel 5
    
        RewriteCond ${REQUEST_URI} !^/phppath
        RewriteRule ^.*$ /index.php [PT]
    </IfModule>   
    

    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.


  2. Check if your server supports mod_rewrite in .htaccess or you may have to write web.config file with the following code

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <directoryBrowse enabled="false"/>
            <rewrite>
                <rules>
                <rule name="APPLICATION: https://<your-host-url>/" patternSyntax="Wildcard">
                    <match url="*"/>
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                        </conditions>
                    <action type="Rewrite" url="index.php"/>
                </rule></rules>
            </rewrite>
        </system.webServer>
    </configuration>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search