代码之家  ›  专栏  ›  技术社区  ›  amazedinc

特定于页面的mod\u重写规则

  •  0
  • amazedinc  · 技术社区  · 6 年前

    我有以下页面结构:

    1. 领域com/页。php?cat=你好(&A);url=世界
    2. 领域com/职业。php?cat=职业和;url=职业
    3. 领域com/文章。php?cat=博客(&W);url=此博客名称

    我希望他们的工作如下:

    1. 领域com/hello/world。html
    2. 领域com/职业/职业。html
    3. 领域com/blog/this blog name。html

    我尝试了以下操作但未成功(mod\u rewrite已启用并确认正常工作):

    RewriteRule ^([^/]*)/([^/]*)\.html$ /careers.php?cat=$1&url=$2 [L]
    RewriteRule ^([^/]*)/([^/]*)\.html$ /page.php?cat=$1&url=$2 [L]
    RewriteRule ^([^/]*)/([^/]*)\.html$ /article.php?cat=$1&url=$2 [L]
    
    1 回复  |  直到 6 年前
        1
  •  4
  •   Syscall Sirajul Islam    6 年前

    您的正则表达式是相同的,因此每次Apache都会排在第一位。

    您可以使用URL的第一部分重定向到已知页面(职业、博客),然后使用您对所有其他页面的表达:

    RewriteRule ^careers/([^/]*)\.html$ /careers.php?cat=careers&url=$1 [L]
    RewriteRule ^blog/([^/]*)\.html$ /article.php?cat=blog&url=$1 [L]
    RewriteRule ^([^/]*)/([^/]*)\.html$ /page.php?cat=$1&url=$2 [L]