user2139268
user2139268

Reputation: 75

CakePHP 2.3 mod_rewrite not working

i have a Problem, written a Webapp in CakePHP 1.3 and it worked fine, so i wanted to use the newer cake version and after copying it on my local Apache (which might have the correct configuration until the older Cake runs fine) it displays the Error that mod_rewrite isn't working. So i dont get it, because if i compare the .htaccess of both cake-versions there are many differences, so i tried to use the old .htaccess for the newer cake 2.3 but got the Error 500.

So i really dont get the issue, because the Apache is definately configured correctly.

Here's what my .htaccess files (cake 2.3.1) contains:

cake/

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

cake/app/

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

cake/app/webroot/

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

Many thanks for your help!

Upvotes: 1

Views: 4444

Answers (1)

mark
mark

Reputation: 21743

My webroot htaccess looks like

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

and works just fine with 2.x

But the recommended way would be

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

as you lined out. That should work in all systems.

see webroot htaccess

Also make sure that mod_rewrite is not just available but allowed to be enabled via htaccess. You will need sth like "AllowOverride All" in your virtual host / config setting. Not everywhere this is the default.

Upvotes: 1

Related Questions