【问题标题】:conditional rules htaccess条件规则 htaccess
【发布时间】:2009-06-26 09:22:34
【问题描述】:

目前,我的 .htaccess 文件看起来像 htis:

IndexIgnore */*
RewriteEngine on
RewriteRule ^add /add.php
RewriteRule ^add/$ add.php
RewriteRule ^sitemap.xml /xmlsitemap.php
RewriteRule ^([^/\.]+)$ /index.php?slug=$1
RewriteRule ^([^/\.]+)/$ /index.php?slug=$1

它适用于以下链接:site.com/category/

但是,我想要 site.com/ 之后的完整 slug。这样我就可以重定向 site.com/category1/subcategory2/subsubcategory3 等。一个类别中可能有未知数量的子类别。

我尝试了 request_uri,但并没有真正奏效。

如何做到这一点?非常感谢!

【问题讨论】:

    标签: .htaccess mod-rewrite conditional


    【解决方案1】:

    编辑:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule .* slug.php?%{QUERY_STRING} [L]
    

    这会将 URL 传递给 slug.php

    【讨论】:

    • 谢谢!但是,如果我这样做,我会得到:domain.com/index.php?slug=index.php
    • 再次感谢.. 它现在保留在 url 中是的。但是...当我在 domain.com/ 后面设置一些东西时,它给了我一个 500 内部服务器错误。 domain.com 工作但是,如果我使用 domain.com/category 它不会
    【解决方案2】:

    好的,知道了。很简单:删除 ^/.从正则表达式。我只是想这意味着它必须停在任何 / :) 但是......谢谢!现在可以了! :)

    【讨论】:

      猜你喜欢
      • 2011-10-02
      • 2013-04-24
      • 1970-01-01
      • 2014-11-09
      • 1970-01-01
      • 1970-01-01
      • 2013-05-23
      • 1970-01-01
      相关资源
      最近更新 更多