【问题标题】:Different rewrite rule in .htaccess.htaccess 中的不同重写规则
【发布时间】:2014-02-02 11:37:40
【问题描述】:

我的 htaccess 中已经有这个重写规则

RewriteCond $1 !^(index\.php)
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?id_user=$1&page=$2 [L]

http://www.mydomain.com/index.php?id_user=user&page=news
http://www.mydomain.com/user/news.html

现在我对新闻详情和活动详情有疑问。

因为有这样的网址(仅适用于页面新闻):

http://www.mydomain.com/user/details-news/category/title-news.html

还有这个(仅用于页面事件)

http://www.mydomain.com/user/event/title-event.html

我可以在 htaccess 中插入新规则以获得这些规则还是我必须编辑我的实际规则?

我的网址对于所有查询都是相同的

index.php?id_user=user&page=details-news&category=category&title=title-news
or
index.php?id_user=user&page=event&title=title-event

任何帮助将不胜感激!

【问题讨论】:

    标签: php apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    你的实际规则只匹配:

    ^([^/]*)/([^/]*)\.html$
    

    网址。

    这意味着只有一个/在里面。所以你可以用更多的斜线添加其他规则,而不需要修改这个实际存在的规则。

    唯一的问题是如果你想用一个 / 添加其他规则。但事实并非如此。

    【讨论】:

      【解决方案2】:

      您可以使用这些规则:

      # skip further rules for files/directories
      RewriteCond %{REQUEST_FILENAME} -d [OR]
      RewriteCond %{REQUEST_FILENAME} -f
      RewriteRule ^ - [L]
      
      RewriteRule ^([^/]+)/([^/.]+)\.html$ /index.php?id_user=$1&page=$2 [L,QSA]
      
      RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html$ /index.php?id_user=$1&page=$2&title=$3 [L,QSA]
      
      RewriteRule ^([^/]+)/^([^/]+)/([^/]+)/([^/.]+)\.html$ /index.php?id_user=$1&page=$2&category=$3&title=$4 [L,QSA]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-25
        • 2011-11-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多