【问题标题】:.htaccess - is it possible to have a combination of static and dynamic url?.htaccess - 是否可以结合使用静态和动态 url?
【发布时间】:2012-12-19 20:24:01
【问题描述】:

目前我使用以下代码在我的 .htaccess 文件中将动态 URL 转换为静态:

RewriteRule ^([a-z0-9_\-]+)$ /index.php?page=$1 [L,NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?page=([^&]+)\ HTTP/
RewriteRule ^index\.php$ http://www.mywebsite.com/%1? [R=301,L]

我想知道的是是否可以更改此规则,以便可以通过www.mywebsite.com/news 访问页面,但也可以附加额外的$_GET 信息,如下所示:www.mywebsite.com/news?id=1

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    你想看看QSA flag,它会在你构造一个查询字符串后追加:

    RewriteRule ^([a-z0-9_\-]+)$ /index.php?page=$1 [L,NC,QSA]
    

    这使得http://www.mywebsite.com/news?id=1 的请求在内部被重写为:/index.php?page=news&id=1

    【讨论】:

      猜你喜欢
      • 2018-12-30
      • 1970-01-01
      • 2012-11-26
      • 2013-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-03
      相关资源
      最近更新 更多