Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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 mod_rewrite和.htaccess 404ing在子目录中_Php_Apache_.htaccess_Mod Rewrite_Http Status Code 404 - Fatal编程技术网

Php mod_rewrite和.htaccess 404ing在子目录中

Php mod_rewrite和.htaccess 404ing在子目录中,php,apache,.htaccess,mod-rewrite,http-status-code-404,Php,Apache,.htaccess,Mod Rewrite,Http Status Code 404,例如: 目录结构 localhost/ |- test/ |- index.php |- .htaccess index.php: <?php if(isset($_GET['cmd'])){ echo "cmd is ok"; } ?> 如果用户设置:http://localhost/test/index.php?cmd=a 输出为:cmd正常 没关系 如果用户设置http://localhost/

例如:

目录结构

localhost/
 |- test/
    |- index.php
    |- .htaccess
index.php

 <?php
        if(isset($_GET['cmd'])){
            echo "cmd is ok";
        }
 ?>

如果用户设置:
http://localhost/test/index.php?cmd=a

输出为:
cmd正常

没关系

如果用户设置
http://localhost/test/a

应该如何设置.htaccess/mod\u rewrite?


上面有代码,我只得到404

您的问题是此处的尾部正斜杠:

RewriteRule ^([^/]+) index.php?cmd=$1 [L]
RewriteRule ^([^/]*)/$ /test/index.php?cmd=$1 [L]
删除该选项或使其成为可选选项:

RewriteRule ^([^/]*)/?$ /test/index.php?cmd=$1 [L]

否则它将与仅以
结尾的url不匹配。../a

您的问题是此处的正斜杠尾随:

RewriteRule ^([^/]*)/$ /test/index.php?cmd=$1 [L]
删除该选项或使其成为可选选项:

RewriteRule ^([^/]*)/?$ /test/index.php?cmd=$1 [L]

否则它将与仅以
结尾的url不匹配。../a

我挣扎了几个小时,就是不明白。请帮帮我。如果你试着问服务器故障,你可能会得到更好的回答。我已经挣扎了好几个小时,就是不明白。请帮助我。如果您尝试在serverfault.com上询问,您可能会得到更好的响应。请明智地添加尾部斜杠选项:
RewriteRule^test/(.+)/?$/test/index.php?cmd=$1[L]
@SpoonNZ-正确。在后面的斜杠后面可能还有更多的东西。我更新了我的答案。谢谢。添加尾随斜杠选项可能是明智的:
RewriteRule^test/(.+)/?$/test/index.php?cmd=$1[L]
@SpoonNZ-正确。在后面的斜杠后面可能还有更多的东西。我更新了我的答案。谢谢。使用
RewriteRule^([^/]*)/$/test/index.php?cmd=$1[L]
我仍然得到了404。使用
RewriteRule^([^/]*)/?$/test/index.php?cmd=$1[L]
-内部服务器错误500。为什么???您必须查看
错误。记录
然后查找实际错误原因。如果经常运行错误,也要设置一个
重写日志(困难)。您可能需要一个
RewriteBase
或其他东西。使用
RewriteRule^([^/]*)/$/test/index.php?cmd=$1[L]
我仍然得到404。使用
RewriteRule^([^/]*)/?$/test/index.php?cmd=$1[L]
-内部服务器错误500。为什么???您必须查看
错误。记录
然后查找实际错误原因。如果经常运行错误,也要设置一个
重写日志(困难)。您可能需要一个
RewriteBase
之类的东西。