Peter Krejci Peter Krejci - 27 days ago 12
Apache Configuration Question

htaccess mod rewrite and slash after index.php

I have following .htaccess file:

RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]


but perhaps because of apache update to version 2.4.23 this one stopped working and browser returns message
file not found
.

I found out, that URL

example.com/auth/login


searches for
index.php
under
{document_root}/auth/login
directory and not directly in
{document_root}
and therefore it's not working. Putting directly
%{DOCUMENT_ROOR}
variable before
index.php
doesn't work, it looks like apache thinks, that document root is the one taken from URL.

How can I rewrite it to index.php with whole path put after index.php?

EDIT
I'm using fcgi and this is my vhost file:

<Directory "/Users/pogo/Development/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>

<VirtualHost *:8080>
ServerName dh
ServerAlias *.dh

VirtualDocumentRoot "/Users/pogo/Development/www/%-2.0.%-1/%0/www"
DirectoryIndex index.html index.php
RewriteEngine On

<FilesMatch \.php$>
SetHandler "proxy:unix:/usr/local/var/run/php5/php5-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>

Answer

You can use this rule:

AcceptPathInfo On
Options +FollowSymLinks
RewriteEngine on

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]

Notice /index.php instead of ./index.php

Comments