SUPER-URGENT! MVC / RewriteRule .htaccess issue on live server

Barry Jones
Barry Jones used Ask the Experts™
on
Hi.

I have an htaccess file that performs MVC routing (file content below).  This works perfectly on local, and staging servers, however fails for some reason on live.

I have ABSOLUTELY no idea whats going on.  If I enter the following url:

http://ggmr.co.uk/home

typically this gets redirected to http://ggmr.co.uk/route.php and the MVC framework kicks in and serves up the correct content.

The problem on live is that the router object receives this:

http://ggmr.co.uk/route.php/home

.. whereas normally it receives this:

http://ggmr.co.uk/home

.. instead.  Why?!?!

htaccess:

#Default document
DirectoryIndex index.php

# Turn rewriting on
Options +FollowSymLinks
RewriteEngine On

# Send request via route.php but only if its not a real file or folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://ggmr.co.uk/route.php/$1 [L]

Open in new window


Currently our site is down and I need help urgently please!!

Thanks, TheFoot
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Change this

RewriteRule ^(.*)$ http://ggmr.co.uk/route.php/$1 [L]


to

RewriteRule ^(.*)$ http://ggmr.co.uk/$1 [L]

Author

Commented:
Hi bportlock - sorry that doesn't work.  route.php MUST receive the request in order to process the route.
I am not sure I fully understand the question. Could it be that the LIVE server has a folder called 'home' whereas the staging servers do not?
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Author

Commented:
no - the folder structure is identical

The request for URL:

ggmr.co.uk/home

gets sent to ggmr.co.uk/route.php for processing.  Normally route.php receivesa "/home" as its URL and so it can work out the route.

On the live server (exactly the same files) it receives "/route.php/home"

Thanks

Author

Commented:
Here is the vhosts conf file, would this affect anything?

<VirtualHost XX:80>
        ServerName XX
        ServerAlias ggmr.co.uk
        ServerAlias www.ggmr.co.uk

        DocumentRoot /var/www/virtual/ggmr/httpdocs
        RewriteEngine on

        ErrorLog        /var/www/virtual/ggmr/error_log
        CustomLog /var/www/virtual/ggmr/access_log "%h %l %u %t \"%r\" %$

        <Directory "/var/www/virtual/ggmr/httpdocs">

        # Adding Deflate Module
                AddOutputFilterByType DEFLATE text/html
                AddOutputFilterByType DEFLATE application/x-httpd-php
                AddOutputFilterByType DEFLATE application/x-httpd-fastphp
                AddOutputFilterByType DEFLATE text/xml
                AddOutputFilterByType DEFLATE text/plain
        # AddOutputFilterByType DEFLATE image/jpeg

        ##### Ending Module configuration

                Allow from all
                AllowOverride All
                Options +FollowSymlinks
                Order allow,deny
        </Directory>

Open in new window

Well, the rule says that if the requesting filename is NOT a special field or folder then the rewrite rule applies.

So if this behaves directly on two machines I would run a comparison of the two folder structures.

When you say that the folder structures are identical, have you run a comparison using diff or some other similar tool?

Are the two servers running identical OS and versions of PHP?

Author

Commented:
Both file systems are identical - I did a comparison via filezilla ftp client.

Live runs Linux PHP v 5.1.6
Staging and dev runs Linux PHP v 5.3.6

I know there are some considerable differences between 5.1 and 5.3, but surely the routing issue is before PHP is even called into play?

route.php is never reached because the URL is changed to a non-existant file (route.php/home) before then by htaccess.  Im convinced its an htaccess problem.  Must be some server configuration that's affecting it..?

Thanks for your help so far..

Author

Commented:
In fact we have had this running just fine on another domain / vhost on the same server, we simply moved the entire file structure into another (live) folder..

.. if that helps any..
Yes - the rewrite is an Apache thing, not a PHP one. The configuration you posted would not affect it.

I may have to go off shortly...

Author

Commented:
ok thanks - appreciate your time..
If, on a command line you type

diff -r /path/to/folder1 /path/to/folder2

only using the correct folder paths, what differences are reported?
I notice that there is no RewriteBase clause in the .htaccess - is it there but just not shown in the code fragment above? Is this folder under an aliased folder?

From the configuration shown above there does not seem to be any aliasing. What differences in folder structure and virtualhosts are there between this folder/host and the one that worked OK?

Author

Commented:
Ran the diff command - no changes at all - excepot for htaccess not having a newline at the end of the file??? Significant?

The htaccess is as I posted - nothing else

By aliased folder do you mean domain alias such as found in the conf file:

ServerAlias ggmr.co.uk
ServerAlias www.ggmr.co.uk

?

Author

Commented:
Added:

RewriteBase /

so now file is:

#Default document
DirectoryIndex index.php

# Turn rewriting on
Options +FollowSymLinks
RewriteBase /
RewriteEngine On

# Send request via route.php but only if its not a real file or folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://www.ggmr.co.uk/route.php/$1 [L] 

Open in new window

I have got to go now. My last suggestion is read this

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase

Good luck

Author

Commented:
Thanks.. appreciate your help..
Just tried it and

ggmr.co.uk/home converts to

http://www.ggmr.co.uk/route.php?route=home

and gives an error of
 
Invalid access.

so that looks a bit better than it was. Anyway, I have someone standing here prodding me to move.

Sorry.....
Put the new line in .htaccess

Author

Commented:
FIXED!  There was an error in the included config file, which was causing the page to report an error, and so route.php caused htaccess to report "Access failed". Stupid, stupid bloody error...!

Thanks for your help bportlock.. much appreciated..

TheFoot
I am glad you got it sorted.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial