【问题标题】:mod rewrite issuemod重写问题
【发布时间】:2012-05-04 08:11:30
【问题描述】:

在 apache .htaccess 文件中,我写过,

RewriteRule ^animals$ index.php?type=animals

它将http://localhost/animals重定向到http://localhost/index.php?type=animals
当 url 键入为 http://localhost/animals/ 时,就会发生错误, 找不到文件。

http://localhost/animalshttp://localhost/animals/ 重定向到http://localhost/index.php?type=animals 的正确语法是什么

【问题讨论】:

    标签: php apache mod-rewrite url-rewriting


    【解决方案1】:

    您应该使用L 标志来标记规则的结束,并使用QSA 来保留新的查询参数,如下所示:

    RewriteRule ^animals/?$ index.php?type=animals [L,QSA,NC]
    

    NC 不用于大小写比较。

    【讨论】:

      【解决方案2】:

      这应该可行:

      RewriteRule ^animals/?$ index.php?type=animals
      

      【讨论】:

        【解决方案3】:

        试试RewriteRule ^animals/?$ index.php?type=animals

        【讨论】:

        • 页面在http://localhost/animals/http://localhost/animals 中打开,但是当我使用http://localhost/animals/ 然后css 时,js 文件不会加载。但使用 http://localhost/animals 时一切都很好。
        • @BhaveshGangani 您应该使用对 css 和 js 文件(以及指向其他 html 页面的链接)的所有引用对您的项目路径进行绝对编码来编写您的 html。因此,如果您的网站位于example.com,则所有指向文件的链接都必须类似于/css/style.css,而不仅仅是css/style.css。如果您的页面位于example.com/yoursite,那么所有链接都必须像/yoursite/css/style.css
        • 他是规则RewriteRule ^animals/?$ index.php?page=animals,目录位于http://localhost/zoo/,当我使用http://localhost/zoo/animals时,请求的页面将是http://localhost/zoo/animalshttp://localhost/zoo/animals/,所有文件都没有问题已加载,当我执行http://localhost/zoo/animals/ 时,页面已加载但未加载 jscss 文件,这是 jsfiddle 代码 jsfiddle.net/H9cvZ/24
        • 当然.htaccess 文件位于localhost/zoo/.htaccess
        【解决方案4】:

        通过设置这条规则来完成,如果指定了基础,那么所有链接都会获得基础路径

        RewriteBase / 
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多