【问题标题】:.htaccess rewritebase + index file url not ofsetting (PHP / Apache).htaccess rewritebase + index file url not ofsetting (PHP / Apache)
【发布时间】:2015-03-16 16:34:20
【问题描述】:

好的,

这是我的 .htaccess,RewriteBase 设置为 /abc/public/。 index.php 文件位于/public/ 文件夹中,该文件夹是/abc/ 的子文件夹。

RewriteEngine On
Options -Indexes
RewriteBase /abc/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

如果我从脚本中检索$_GET['url'] 值,则$url[0] 索引处始终存在public 值。现在,如果重写基数设置为 /abc/public/,为什么将 public 传递给 index.php?

它不应该在 /public/ 之后才开始传递值吗?所以说我有/abc/public/method/params/,如果我输出print_r($url),我不应该得到$url[0] = 'method', $url[1] = 'params'吗??

似乎无法弄清楚这一点。

编辑:

模组,请忽略最后一个标志。事实证明这个问题毕竟是相关的。

【问题讨论】:

  • 如何将$_GET['url'] 变成$url? split()? "public" 不应在 $_GET['url'] 中。
  • 对不起,我只是在一个函数中解析它:return (isset($_GET['url'])) ? str_ireplace('-', '', explode('/', filter_var(rtrim($_GET['url'], '/')), FILTER_SANITIZE_URL)) : null;
  • 好的,那么$_GET['url'] 的价值是什么?
  • 例如,如果我访问'/public/abc/',那么进入我的解析函数的值是'public/abc'。如果我只有 '/public/',则 parse 函数将返回 null,因为它认为 $_GET['url'] 为空。
  • 好的,所以我将 .htaccess 放在 /public/ 文件夹中,现在可以了。 @anubhava 如果您想根据您的问题做出回答,我会接受

标签: php apache .htaccess mod-rewrite


【解决方案1】:

根据您的 RewriteBase 值,我认为 .htaccess 未放置在正确的目录中。例如,如果您正在使用:

RewriteBase /abc/public/

那么.htaccess的正确位置应该是:

%{DOCUMENT_ROOT}/abc/public/

【讨论】:

    猜你喜欢
    • 2022-12-03
    • 2013-05-17
    • 2013-08-27
    • 2020-06-21
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 2012-03-14
    • 1970-01-01
    相关资源
    最近更新 更多