繁体   English   中英

.htaccess / url重写问题

[英].htaccess / url rewrite issues

使用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/公共/事件

我正在使用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';

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

为了澄清我上面的评论,您要修改的代码可能在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');
    }

当然取决于主机目录的结构。

您必须更改每个.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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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