.htaccess / url重写问题

时间:2012-06-17 15:07:28

标签: php .htaccess cakephp mod-rewrite cakephp-2.0

使用CakePHP。该网站是www.villapalmeras.co.uk。当我查看根时,我的链接正确显示(即http://www.villapalmeras.co.uk/public/events)。当我导航到任何其他页面时,相同的链接会显示为http://www.villapalmeras.co.uk/websites/123reg/LinuxPackage25/jo/rd/an/jordanwallwork.co.uk/public_html/domains/villalaspalmeras/public/events

我正在使用123-reg主机包,并已将villapalmeras.co.uk域映射到位置域/ villapalmeras(这是我的网站jordanwallwork.co.uk的根)。尝试编辑.htaccesses文件但没有成功。

我的.htaccess文件是:

/domains/villapalmeras/.htaccess:

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

/domains/villapalmeras/app/.htaccess:

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

/domains/villapalmeras/app/webroot/.htaccess

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

的index.php:

define('APP_DIR', 'app');
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
    define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
}

require APP_DIR . DS . WEBROOT_DIR . DS . 'index.php';

3 个答案:

答案 0 :(得分:2)

原来答案很简单!我需要做的就是将RewriteBase /添加到所有.htaccess文件中,而不仅仅是根目录,然后才能完美地运行

答案 1 :(得分:0)

为了澄清我上面的评论,你要修改的代码可能在你的index.php中:

您正在寻找的代码:

/**
 * The full path to the directory which holds "app", WITHOUT a trailing DS.
 *
 */
    if (!defined('ROOT')) {
        define('ROOT', dirname(dirname(dirname(__FILE__))));
    }
/**
 * The actual directory name for the "app".
 *
 */
    if (!defined('APP_DIR')) {
        define('APP_DIR', basename(dirname(dirname(__FILE__))));
    }
/**
 * The absolute path to the "cake" directory, WITHOUT a trailing DS.
 *
 */
    if (!defined('CAKE_CORE_INCLUDE_PATH')) {
        define('CAKE_CORE_INCLUDE_PATH', ROOT);
    }

应该改为更像:

/**
 * The full path to the directory which holds "app", WITHOUT a trailing DS.
 *
 */
    if (!defined('ROOT')) {
        define('ROOT', DS . 'home' . DS . 'username');
    }
/**
 * The actual directory name for the "app".
 *
 */
    if (!defined('APP_DIR')) {
        define('APP_DIR', 'domain.com');
    }
/**
 * The absolute path to the "cake" directory, WITHOUT a trailing DS.
 *
 */
    if (!defined('CAKE_CORE_INCLUDE_PATH')) {
        define('CAKE_CORE_INCLUDE_PATH', 'home' . DS . 'username');
    }

根据主机目录的结构而定。

答案 2 :(得分:0)

您必须更改每个.htaccess,而无需更改index.php或其他文件。

/domains/villapalmeras/.htaccess:

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

/domains/villapalmeras/app/.htaccess:

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

/domains/villapalmeras/app/webroot/.htaccess

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