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
Php htaccess赢得';在添加索引之前,请不要加载索引_Php_.htaccess - Fatal编程技术网

Php htaccess赢得';在添加索引之前,请不要加载索引

Php htaccess赢得';在添加索引之前,请不要加载索引,php,.htaccess,Php,.htaccess,我正在尝试从URL中删除文件夹,我做到了,但问题是当我访问domain.com时,它显示错误500,但如果我添加domain.com/index.php,它将工作 RewriteEngine On RewriteBase /insta/member/ RewriteCond %{REQUEST_FILENAME}.php -f RewriteCond %{REQUEST_URI} !/$ RewriteRule (.*) $1\.php [L] RewriteCond %{THE_REQUE

我正在尝试从URL中删除文件夹,我做到了,但问题是当我访问domain.com时,它显示错误500,但如果我添加domain.com/index.php,它将工作

RewriteEngine On
RewriteBase /insta/member/

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+insta/member/pages/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^insta/member/pages)^(.*)$ /insta/member/pages/$1 [L,NC]

这不是我的驾驶室,但我很确定你需要:

DirectoryIndex index.php 
可在此处找到:


编辑:经过一些对话后,这可能不是问题所在,而是此处描述的无限循环:

这不是我的驾驶室,但我很确定您需要:

DirectoryIndex index.php 
可在此处找到:


编辑:经过一段对话后,这可能不是问题所在,而是此处描述的无限循环:

在这组规则中,看起来请求始终被视为文件,如果请求文件名不是文件,则会向其添加
.php
。但情况并非总是如此。在

REQUEST_FILENAME:匹配请求的文件或脚本的完整本地文件系统路径,如果在引用REQUEST_FILENAME时服务器已经确定了该路径。否则,例如在虚拟主机上下文中使用时,将使用与请求URI相同的值

因此,请求文件名可以解析为文件、文件夹或目录 (这在其他web服务或其他apache版本中可能有所不同)。对于文件,规则有效,否则将失败。例如,
//domain.com
将解析为文档根。但是
//domain.com/index.php
将解析为文档根目录中的index.php文件。为了避免这种混淆,一般来说,应该考虑所有三种可能性。另外,
请求文件名
本身可能是一个没有.php的文件,类似于
//domain.com/my_styles.css
。在这种情况下,规则也失败了。 以下一套规则应该有效

    RewriteEngine On
    RewriteBase /insta/member/

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule (.*) $1\.php [L]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+insta/member/pages/([^\s]+) [NC]
    RewriteRule ^ %1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (?!^insta/member/pages)^(.*)$ /insta/member/pages/$1 [L,NC]
编辑: 对第一组规则的解释是,它正在检查请求的解析文件名部分是否不是目录、链接或文件,“filename.php”是文件,并且不是以正斜杠结尾,然后将.php添加到请求中

回答关于pretty url的评论中的问题:

要获得漂亮的url,您需要了解应用程序路由。要从查询字符串中删除GET参数,如
?checking=value
规则应如下所示

RewriteRule (.*)/checking/(.*)$ $1?checking=$2 [L]
将以下内容与上述规则相结合

    RewriteEngine On
    RewriteBase /insta/member/

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)/checking/(.*)$ $1\.php?checking=$2 [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule (.*) $1\.php [QSA,L]
然后,
$\u获取以下示例的值

    http://localhost/insta/member/test
    array (size=0)
      empty

    http://localhost/insta/member/test?checking=value
    array (size=1)
      'checking' => string 'value' (length=5)       

    http://localhost/insta/member/test/checking/value
    array (size=1)
      'checking' => string 'value' (length=5)

    http://localhost/insta/member/test/checking/value?second=2
    array (size=2)
      'checking' => string 'value' (length=5)
      'second' => string '2' (length=1)
最后,这里是
check/ig/value
check?ig=value
check.php?ig=value
的具体规则

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)/(.*)/(.*)$ $1.\php?$2=$3 [QSA,L]
GET

    http://localhost/insta/member/check/ig/value
    array (size=1)
      'ig' => string 'value' (length=5)

在这组规则中,看起来请求总是被认为是文件,如果请求文件名不是文件,那么它会向其中添加
.php
。但情况并非总是如此。在

REQUEST_FILENAME:匹配请求的文件或脚本的完整本地文件系统路径,如果在引用REQUEST_FILENAME时服务器已经确定了该路径。否则,例如在虚拟主机上下文中使用时,将使用与请求URI相同的值

因此,请求文件名可以解析为文件、文件夹或目录 (这在其他web服务或其他apache版本中可能有所不同)。对于文件,规则有效,否则将失败。例如,
//domain.com
将解析为文档根。但是
//domain.com/index.php
将解析为文档根目录中的index.php文件。为了避免这种混淆,一般来说,应该考虑所有三种可能性。另外,
请求文件名
本身可能是一个没有.php的文件,类似于
//domain.com/my_styles.css
。在这种情况下,规则也失败了。 以下一套规则应该有效

    RewriteEngine On
    RewriteBase /insta/member/

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule (.*) $1\.php [L]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+insta/member/pages/([^\s]+) [NC]
    RewriteRule ^ %1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (?!^insta/member/pages)^(.*)$ /insta/member/pages/$1 [L,NC]
编辑: 对第一组规则的解释是,它正在检查请求的解析文件名部分是否不是目录、链接或文件,“filename.php”是文件,并且不是以正斜杠结尾,然后将.php添加到请求中

回答关于pretty url的评论中的问题:

要获得漂亮的url,您需要了解应用程序路由。要从查询字符串中删除GET参数,如
?checking=value
规则应如下所示

RewriteRule (.*)/checking/(.*)$ $1?checking=$2 [L]
将以下内容与上述规则相结合

    RewriteEngine On
    RewriteBase /insta/member/

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)/checking/(.*)$ $1\.php?checking=$2 [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule (.*) $1\.php [QSA,L]
然后,
$\u获取以下示例的值

    http://localhost/insta/member/test
    array (size=0)
      empty

    http://localhost/insta/member/test?checking=value
    array (size=1)
      'checking' => string 'value' (length=5)       

    http://localhost/insta/member/test/checking/value
    array (size=1)
      'checking' => string 'value' (length=5)

    http://localhost/insta/member/test/checking/value?second=2
    array (size=2)
      'checking' => string 'value' (length=5)
      'second' => string '2' (length=1)
最后,这里是
check/ig/value
check?ig=value
check.php?ig=value
的具体规则

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)/(.*)/(.*)$ $1.\php?$2=$3 [QSA,L]
GET

    http://localhost/insta/member/check/ig/value
    array (size=1)
      'ig' => string 'value' (length=5)

当我删除.htaccess中的所有内容时,这种方法效果很好,所以这是代码@Баааа的问题。我不明白,这是.htaccess的代码。这里有一个不同的参考,建议添加同一行:@Бааааа。我想我看到了我的沟通失误。我不是建议你下载一个工具或任何东西。我相信,“DirectoryIndex.php”是.htaccess文件的标准语法,其中“index.php”是在不进一步指定路径的情况下要提供服务的文件的名称。或者我没能理解这个问题。我一行一行地删除,当我删除最后两行时,它的工作原理,这有助于使它成为焦点。我是这么想的。htaccess可能会覆盖上游的设置,但你的评论让人觉得根本不可能。不管怎样,我相信我还是无意中找到了你的答案。看起来你正在捕获你正在导致一个无限循环,因为你的条件是在修改后捕获你的URL,修改它们,然后一遍又一遍地将它们发送回来。我在Supreme中玩了一点正则表达式,它通过了嗅探测试。当我删除.htaccess中的所有内容时,这种方法效果很好,所以这是代码@Баааа的问题。我不明白,这是.htaccess的代码。这里有一个不同的参考