Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php .htaccess/url重写问题_Php_.htaccess_Cakephp_Mod Rewrite_Cakephp 2.0 - Fatal编程技术网

Php .htaccess/url重写问题

Php .htaccess/url重写问题,php,.htaccess,cakephp,mod-rewrite,cakephp-2.0,Php,.htaccess,Cakephp,Mod Rewrite,Cakephp 2.0,使用CakePHP。网站是www.villapalmeras.co.uk。当我查看根目录时,我的链接显示正确(即)。当我导航到任何其他页面时,相同的链接显示为 我正在使用一个123 reg托管包,并已将villapalmeras.co.uk域映射到location domains/villapalmeras(这是我在jordanwallwork.co.uk的网站的根)。尝试编辑.htaccess文件,但未成功 我的.htaccess文件是: /domains/villapalmeras/.hta

使用CakePHP。网站是www.villapalmeras.co.uk。当我查看根目录时,我的链接显示正确(即)。当我导航到任何其他页面时,相同的链接显示为

我正在使用一个123 reg托管包,并已将villapalmeras.co.uk域映射到location domains/villapalmeras(这是我在jordanwallwork.co.uk的网站的根)。尝试编辑.htaccess文件,但未成功

我的.htaccess文件是:

/domains/villapalmeras/.htaccess:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [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';
您要查找的代码:

/**
 * 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');
    }

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

结果证明答案非常简单!我所需要做的就是将
RewriteBase/
添加到所有.htaccess文件中,而不仅仅是根文件,然后它就可以完美地工作了

您必须更改每个.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>
/domains/villapalmeras/.htaccess:
重新启动发动机
重写基/
重写规则^$app/webroot/[L]
重写规则(*)app/webroot/$1[L]
/domains/villapalmeras/app/.htaccess:
重新启动发动机
重写库/应用程序/
重写规则^$webroot/[L]
重写规则(.*)webroot/$1[L]
/domains/villapalmeras/app/webroot/.htaccess
重新启动发动机
重写base/app/webroot/
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)$index.php[QSA,L]

您能从index.php发布根目录、应用目录和蛋糕核心路径吗?若这些配置正确,你们就不必去搞.htaccess了。我真的很想提高投票率,但你们的代表分数是777!我就是不能!不要这样做!我将失去权限!更不用说对我的运气的不利影响了。谢谢,我甚至没有意识到该文件中有可配置的设置!!我会看一看,但我还包括了当前的设置,以防您发现问题,尝试执行die(debug());在组成路径的变量字符串上,查看它们是否真的为您的应用程序、应用程序的webroot等创建了正确的路径。所有内容都可能会检查出来,但这样做应该能让您很好地了解这些路径是否设置正确。
/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>