【问题标题】:How to create pretty url using htaccess [duplicate]如何使用 htaccess 创建漂亮的 url [重复]
【发布时间】:2016-11-06 13:18:29
【问题描述】:

我有一个类似http://example.com/file.php?id=7gJKw2&d=78sfmnnsd8的链接

我想把上面的网址设为

http://example.com/file/7gJKw2/78sfmnnsd8

这是我尝试过的

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

如何添加d 的值并使其好看?

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting friendly-url pretty-urls


    【解决方案1】:

    您可以将整个a-zA-Z0-9_ 模式捆绑成一个简单的\w。至于真正的问题,只需将第二部分添加如下:

    RewriteRule ^file/([\w.-]+)/([\w.-]+)/?$ file.php?id=$1&d=$2 [L]
    RewriteRule ^file/([\w.-]+)/?$ file.php?id=$1 [L]
    

    【讨论】:

      猜你喜欢
      • 2012-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-02
      • 2019-02-27
      • 1970-01-01
      • 2016-01-25
      • 1970-01-01
      相关资源
      最近更新 更多