例如:
目录结构
localhost/
|- test/
|- index.php
|- .htaccess
的index.php :
<?php
if(isset($_GET['cmd'])){
echo "cmd is ok";
}
?>
的.htaccess
RewriteEngine On
RewriteRule ^([^/]*)/$ /test/index.php?cmd=$1 [L]
如果用户设置:http://localhost/test/index.php?cmd=a
输出将是:cmd is ok
没关系!
如果用户设置http://localhost/test/a
如何设置.htaccess / mod_rewrite?
有了代码,我就得到404.
答案 0 :(得分:5)
RewriteRule ^([^/]+) index.php?cmd=$1 [L]
答案 1 :(得分:1)
你的问题是这里的结尾斜线:
RewriteRule ^([^/]*)/$ /test/index.php?cmd=$1 [L]
删除它或使其成为可选:
RewriteRule ^([^/]*)/?$ /test/index.php?cmd=$1 [L]
否则它与仅以.../a