doushuo8677
doushuo8677
2013-12-23 23:55

CakePHP 2.4.3 URL重写模块无法正常工作

已采纳

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • doupi6737 doupi6737 8年前

    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.

    点赞 评论 复制链接分享
  • dtjw6660 dtjw6660 8年前

    /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

    点赞 评论 复制链接分享
  • douxihui8270 douxihui8270 8年前

    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.

    点赞 评论 复制链接分享

相关推荐