【问题标题】:htaccess is redirecting to "webroot" every time that a request without end trailling is done每次完成没有尾随的请求时,htaccess 都会重定向到“webroot”
【发布时间】:2014-10-22 10:19:20
【问题描述】:

我有以下项目结构:

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>

.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>

当我请求/news(作为框架管理的漂亮URL)时,请求被apache重定向到/webroot/news/,而不是加载新闻。我找不到问题所在,您的建议是什么?

所以,如果我点击:news,页面将重定向到/webroot/news/。如果我点击:news/,页面将重定向到/news/ (使用 cPanel 域内的子域)

【问题讨论】:

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

标签: .htaccess cakephp mod-rewrite url-rewriting cakephp-2.3


【解决方案1】:

由于mod_dirmod_dir 之后添加了一个尾部斜杠,因此请在您的根 .htaccess 中关闭目录尾部斜杠。作为最后一条规则,在内部再次添加尾部斜杠:

.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>

【讨论】:

    【解决方案2】:

    public_html/app/.htaccess

    Deleted file
    

    public_html/app/webroot/.htaccess

    <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_html/app/webroot/

    已解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-10
      • 2023-03-12
      • 1970-01-01
      • 2020-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多