Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
.htaccess htaccess正在重定向到";webroot“;每次完成一个没有结束跟踪的请求时_.htaccess_Cakephp_Mod Rewrite_Url Rewriting_Cakephp 2.3 - Fatal编程技术网

.htaccess htaccess正在重定向到";webroot“;每次完成一个没有结束跟踪的请求时

.htaccess htaccess正在重定向到";webroot“;每次完成一个没有结束跟踪的请求时,.htaccess,cakephp,mod-rewrite,url-rewriting,cakephp-2.3,.htaccess,Cakephp,Mod Rewrite,Url Rewriting,Cakephp 2.3,我的项目结构如下: public_html/ |- app/ |- webroot/ |- news -> symlink to ../../news/webroot/ |- .htaccess (see code 1) |- .htaccess (see code 2) |- news/ |- webroot/ .htaccess 1 <IfModule mod_rewrite.c> RewriteEngine on

我的项目结构如下:

public_html/
|- app/
   |- webroot/
      |- news -> symlink to ../../news/webroot/
      |- .htaccess (see code 1)
   |- .htaccess (see code 2)
|- news/
   |- webroot/
.htaccess 1

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

重新启动发动机
重写基/
重写规则^$webroot/[L]
重写规则(.*)webroot/$1[L]
.htaccess 2

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/(img|css|js|fonts)/(.*)$
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_URI}^/(img | css | js |字体)/(*)$
重写规则^(.*)$index.php[QSA,L]
当我请求
/news
(作为框架管理的漂亮URL)时,apache会将请求重定向到
/webroot/news/
,而不是加载新闻。我找不出哪里不对,你有什么建议

因此,如果我单击:
news
,页面将重定向到
/webroot/news/
。如果我单击:
news/
页面将重定向到
/news/

(使用cPanel域内的子域)

在根目录中关闭目录尾部斜杠。htaccess因为
mod\u dir
mod\u dir
之后添加尾部斜杠。最后一条规则是在内部再次添加尾部斜杠:

.htaccess 1:

<IfModule mod_rewrite.c>
    DirectorySlash Off
    RewriteEngine on
    RewriteBase /

    RewriteRule (.*) webroot/$1 [L]

    # add trailing slash for directories
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.+)/$ $1 [L,NE]
</IfModule>

目录删除
重新启动发动机
重写基/
重写规则(.*)webroot/$1[L]
#为目录添加尾部斜杠
RewriteCond%{REQUEST_FILENAME}-d
重写规则^(+)/$$1[L,NE]

public\u html/app/.htaccess

Deleted file
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/(img|css|js|fonts)/(.*)$
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
public\u html/app/webroot/.htaccess

Deleted file
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/(img|css|js|fonts)/(.*)$
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_URI}^/(img | css | js |字体)/(*)$
重写规则^(.*)$index.php[QSA,L]
指向public\u html/app/webroot/


已解决。

如果您的子域指向public\u html/app,则应删除符号链接public\u html/app/webroot/news,否则Apache会找到它,并且不会将URL传递到index.php。此外,CakePHP附带的默认.htaccess没有RewriteBase选项。@savedario My app ponts to public_html/app/webroot。这不是默认的htaccess。符号链接将不匹配,因此,
RewriteCond
规则将按预期作为正常请求提供。