简体   繁体   中英

CakePHP 2.4.3 URL-Rewriting module not working

Ok...

Getting tired of this issue. So I thought I would ask here

Just to clarify I did follow the Cake PHP documentation on this. I did google this for almost 2 hours and guess what ... no luck

  1. I did enable the mod-rewrite -> this took me a while as I dont have an httpd.conf file
  2. I edited my htaccess file in webroot etc to include:

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

As recommended by another poster on this site

No Luck. Am I missing something special here like a tad of mystical unicorn dust on my installation or am I being stupid?

Lemme know if you need something else

Oh I did a LAMP installation thing a while ago

Your guidance will be much appreciated :)

[edit] cahnged tags to 2.4 instead of 2.3 <-- My bad

If you had to enable mod_rewrite then chances are, your default apache setup will also need to be changed to allow the .htaccess to execute correctly. By default, most .htaccess rules in publicly accessible directories will be denied.

Depending on your setup you should have something like this ...

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order deny,allow
    deny from all
</Directory>

Found in your config directory for a apache, which may be something like

/etc/apache2/sites-available/default

Note that the path above and also the /var/www/ path in your Directory tag above, may be different.

You will need to change a few things, such as AllowOveride and also a few others to match below. Inspect for the differences.

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Once you have changed that, restart apache and hopefully you will see that the rules in your .htaccess file are now executing.

I think you're missing the /$1 part.

My .htaccess in webroot looks like this:

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

I have also had issues in the past with rewrite and cakePHP on some servers, I needed to add a slash at the start of the filename, as shown:

RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]

however I don't think that this is your issue here.

/var/www/app/webroot/.htaccess

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

/var/www/app/.htaccess

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

/var/www/.htaccess

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

Please use these .htaccess files to configure you app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM