【问题标题】:Issue with URL slug.URL slug 的问题。
【发布时间】:2013-06-25 15:44:51
【问题描述】:

我似乎无法获得 url slug 的第二部分。我目前有这样的 .htaccess 文件:

RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?id=$1

得到这个:

http://example.com/user/john

现在无法让它工作:

 http://example.com/user/john?o=last

如何获取$_GET['o']

【问题讨论】:

标签: php .htaccess url slug


【解决方案1】:
  1. 您需要 QSA(查询字符串附加)标志以在重定向时保留现有查询。
  2. 您不需要 2 条规则来处理尾部斜杠。

用这个替换你的代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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

【讨论】:

    猜你喜欢
    • 2015-06-03
    • 2016-03-28
    • 2011-05-30
    • 2011-08-04
    • 2011-02-08
    • 2017-07-02
    • 2020-03-17
    • 1970-01-01
    • 2011-09-19
    相关资源
    最近更新 更多