0
votes

I have three web servers on three separate computers. I am trying to install a php application that rewrites all url requests to index.php (front controller pattern). The following .htaccess works on two out of the three web servers:

RewriteEngine On
# Redirect everything to the Front Controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^(css|images|files)/ index.php [NC,L]

So, when I visit http://example.com/hithere, index.php is called and I can then parse the originally requested url (hithere) to figure out what controller to send it to.

However, for some unknown reason, the above .htaccess file doesn't work on the third webserver. Instead, when I access http://example.com/hithere, I get a 404 not found error in my browser that says this:

The requested URL /full/path/to/application/index.php was not found on this server.

So, based on the above error, I can tell that it's actually trying to redirect to index.php. But the file that the browser lists in the /full/path/... below is actually on my web server - so I have no idea why it can't find it. Could someone please help me and tell me what I'm doing wrong?

Edit: I don't know if something in the httpd.conf could be conflicting, but here are the settings I have in httpd.conf for the directory that this application is in

Alias /myapp /full/path/to/my/app
<Directory /full/path/to/my/app>
Order allow,deny
AllowOverride All
Allow from all
</Directory>

Edit 2: I noticed something peculiar in the Apache logs. It looks Apache is appending index.php, which I am trying to redirect traffic to, to the DocumentRoot:

File does not exist: /document/root/full/path/to/my/app/index.php

When it should be going to:

/full/path/to/my/app/index.php

So I basically need to tell htaccess to ignore the document root. I tried this by specifying this in my .htaccess file:

RewriteBase /full/path/to/my/app/

But it's still searching the document root for index.php :/ Is there a way to reset the DocumentRoot or tell htaccess to ignore it when rewriting to index.php? Even when I use the absolute path in the RewriteRule, it still appends it to the document root.

RewriteEngine On
# Redirect everything to the Front Controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^(css|images|files)/ /full/path/to/my/app/index.php [NC,L]

It doesn't make sense to me... Can someone please help?

Thanks

3
Does the third web server have mod_rewrite enabled?faffaffaff
Does the third web server have AllowOverride set to a sufficient high level for the directory your .htaccess is placed in?faffaffaff
@faffaffaff yes, httpd.conf file has AllowOverride All. I have edited the question with the relevant httpd.conf settings for this application, maybe it's something in there? Thanks for your helpjerry
Check your apache logs.Rob W
Can you show output of ls -lZ /full/path/to/application/ ?anubhava

3 Answers

0
votes

So, based on the above error, I can tell that it's actually trying to redirect to index.php. But the file that the browser lists in the /full/path/... below is actually on my web server - so I have no idea why it can't find it.

Assuming it's a *nix alike system, you might want to check file permissions and make sure that the webserver has read access to the file.

0
votes

You also need to check the DocumentRoot parameter in httpd.conf Look for something like this in the file and make sure it's correct. That is also where apache will be getting it from.

DocumentRoot "/var/www/html/path/to/whatever"

Also I would disable SELinux if it's on and you really don't need it because it causes weird problems too.

0
votes

First enable rewrite module in apache by using $ sudo a2enmod rewrite then restart web server by $ sudo systemctl restart apache2 Put following code in your virtual host.

<Directory /var/www/html/your_app_folder>
    Order allow,deny
    AllowOverride All
    Allow from all
</Directory>

then add following code in your .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>