[英]mod_rewrite and .htaccess 404ing in a subdirectory
For example: 例如:
Dir structure 目录结构
localhost/
|- test/
|- index.php
|- .htaccess
index.php : index.php :
<?php
if(isset($_GET['cmd'])){
echo "cmd is ok";
}
?>
.htaccess .htaccess
RewriteEngine On
RewriteRule ^([^/]*)/$ /test/index.php?cmd=$1 [L]
If user sets: http://localhost/test/index.php?cmd=a
如果用户设置:
http://localhost/test/index.php?cmd=a
Output will be: cmd is ok
输出将是:
cmd is ok
That is ok! 那没问题!
I want to get same result if user sets http://localhost/test/a
如果用户设置
http://localhost/test/a
我想得到相同的结果
How should .htaccess/mod_rewrite be set ? .htaccess / mod_rewrite应该如何设置?
With code up there, I just get 404. 有了代码,我就得到了404。
RewriteRule ^([^/]+) index.php?cmd=$1 [L]
Your problem is the trailing forward slash here: 您的问题是此处的尾部正斜杠:
RewriteRule ^([^/]*)/$ /test/index.php?cmd=$1 [L]
Remove that or make it optional: 删除它或使其可选:
RewriteRule ^([^/]*)/?$ /test/index.php?cmd=$1 [L]
Else it won't match the url that ends with just .../a
否则,它将不匹配以
.../a
结尾的URL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.