首页 文章

apache RewriteRule没有效果但是ErrorDocument效果

提问于
浏览
0

我启用了.htaccess Apache功能 . 对于我的localhost wamp它有效,因为ErrorDocument 404效果,但似乎只有RewriteRule不起作用,我写的是否有问题?如何编写Annotated语句?非常感谢!这些网址不起作用:

1.RewriteRule ^ http://localhost/app/track/([0-9]+) $ /index.php?app=$1

2.RewriteRule ^ http://localhost/app/track/123 $ /index.php?app=123
enter image description here

enter image description here

1 回答

  • 0

    对于:

    RewriteRule ^ localhost / app / track /([0-9])$ /index.php?app=$1

    RewriteRule ^ localhost / app / track / 123 $ /index.php?app=123

    删除'localhost /',效果很好 .

    我认为正则表达式模式不匹配,因为我的DocumentRoot带有'/' .

    /////

    为了帮助理解,我通过php编写了伪代码,参考,欢迎更正:)

    $realPath = str_replace('http://localhost',DocumentRoot,$url);
    redirect(test($realPath));
    function test($realPath) {
        $pass = false;
        if(preg_match($argRegExp, str_replace(DocumentRoot, '', $realPath))) {
            if(strpos($argRewriteUrl,'?') ===false){
                $realPath = $argRewriteUrl.'/'.basename($realPath);
                $pass = $realPath;
            }else{
                getArgs($realPath);//split ?xx=xx&...
            }
            if($realPath) {
                if($r = test($realPath)){
                    $pass = $r;
                }
            }
        }
        if($pass) {
            if($r = test($realPath)){
                $pass = $r;
            }
        }
        return $pass;
    }
    

相关问题