重写使用htaccess不能正常工作的参数

时间:2015-06-10 19:27:57

标签: php .htaccess mod-rewrite

我现在已经搜索了大约2个小时,并尝试了所有解决方案,但仍然无法弄清楚我做错了什么。我正在写一个api。我试图使用"漂亮"网址而不是传递参数。

当我致电myurl.com/categories时,它会正确返回整个类别列表。

当我调用myurl.com/categories/1,然后获取id = 1的类别时,会返回404错误。

当我致电myurl.com/categories?id=1时,它成功返回id = 1的类别。

这是我的.htaccess

RewriteEngine On
RewriteRule ^categories/([0-9]+)$ /categories.php?id=$1 [L,NC]
RewriteRule ^([^\.]+)$ $1.php [L,NC]

任何想法我做错了什么?

2 个答案:

答案 0 :(得分:0)

将.htaccess更改为:

<!doctype html>
<html ng-app="ui.bootstrap.demo">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.0.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

<div ng-controller="ProgressDemoCtrl">

    <h3>Static</h3>
    <div class="row">
        <div class="col-sm-4"><progressbar value="55"></progressbar></div>
        <div class="col-sm-4"><progressbar class="progress-striped" value="22" type="warning">22%</progressbar></div>
        <div class="col-sm-4"><progressbar class="progress-striped active" max="200" value="166" type="danger"><i>166 / 200</i></progressbar></div>
    </div>

    <hr />
    <h3>Dynamic <button class="btn btn-sm btn-primary" type="button" ng-click="random()">Randomize</button></h3>
    <progressbar max="max" value="dynamic"><span style="color:black; white-space:nowrap;">{{dynamic}} / {{max}}</span></progressbar>

    <small><em>No animation</em></small>
    <progressbar animate="false" value="dynamic" type="success"><b>{{dynamic}}%</b></progressbar>

    <small><em>Object (changes type based on value)</em></small>
    <progressbar class="progress-striped active" value="dynamic" type="{{type}}">{{type}} <i ng-show="showWarning">!!! Watch out !!!</i></progressbar>

    <hr />
    <h3>Stacked <button class="btn btn-sm btn-primary" type="button" ng-click="randomStacked()">Randomize</button></h3>
    <progress><bar ng-repeat="bar in stacked track by $index" value="bar.value" type="{{bar.type}}"><span ng-hide="bar.value < 5">{{bar.value}}%</span></bar></progress>

</div>
  </body>
</html>

答案 1 :(得分:0)

以这种方式尝试您的规则,并使Trip ('A', 'B', 1.0, 2.0) used: 0.0 Trip ('B', 'C', 2.0, 3.0) used: 0.0 Trip ('C', 'B', 3.5, 4.5) used: 0.0 Trip ('B', 'A', 4.5, 5.5) used: 0.0 Trip ('D', 'E', 1.0, 5.5) used: 1.0 也可选。

dist = {("A", "B"): 2.0,
        ("B", "C"): 2.0,
        ("D", "E"): 3.0}