【问题标题】:htaccess rewrite rule with multiple parameters具有多个参数的 htaccess 重写规则
【发布时间】:2013-05-16 11:13:38
【问题描述】:

这是我的.htaccess 文件:

Options +FollowSymLinks
Options -Multiviews

RewriteEngine On
RewriteBase /website/

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [S=20]

RewriteRule ^(.*)$ $1.php 
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ index.php?occ=$1&cat=$2

现在这两条线一起不起作用,例如:

如果我要去contact.php,我会输入我的网址:localhost/website/contact 它会工作

但是,如果我想通过在我的 url 中输入以下内容来转到 location/website/index.php?occ=occasion&cat=category:localhost/website/occasion/category,它只有在我删除第一个重写规则时才有效

但是我不能再去本地主机/网站/联系人了

我在这里错过了什么?

【问题讨论】:

    标签: php .htaccess mod-rewrite


    【解决方案1】:

    您的问题是您的订单。

    /website/occasion/category 首先被重写为/website/occasion/category.php,然后无法匹配第二条规则。

    RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ index.php?occ=$1&cat=$2 [L]
    RewriteRule ^(.*)$ $1.php
    

    更改顺序并将[L] 参数添加到规则(成功执行后停止执行后续规则)应该可以解决问题。

    【讨论】:

      【解决方案2】:
      RewriteEngine on
      
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      
      RewriteRule ^site_1/(.*)$ site_1/index.php?/$1 [L]
      RewriteRule ^site_2/(.*)$ site_2/index.php?/$1 [L]
      

      在网站中,您不会拥有 1000 多个网站,您可以声明您想要的链接和文件夹名称 例如 如果你的结构是

      /home/site1, /home/site2
      

      链接会像http://yourdomain.com/medical & http://yourdomain.com/entertainment

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-14
        • 1970-01-01
        • 2013-12-26
        • 2021-09-17
        • 1970-01-01
        • 1970-01-01
        • 2015-02-15
        相关资源
        最近更新 更多