【问题标题】:Mod-rewrite; apache rules模组重写;阿帕奇规则
【发布时间】:2013-02-09 00:00:20
【问题描述】:
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_]+)$ index.php?paste=$1 [L] 

正如您在上面看到的,它需要site.com/index.php?paste=pasteID 并将其转换为site.com/pasteID

现在我想知道一种可以像这样编辑粘贴的方法。

site.com/index.php?paste=pasteID&page=edit
site.com/pasteID/edit

反正我可以做到吗?

【问题讨论】:

  • 您对规则的解释不正确,也许这就是您的困惑所在:您的规则是这样做的:它们在内部将site.com/pasteID 的请求重写为site.com/index.php?paste=pasteID&page=edit。所以反过来。配置服务器时,始终从 客户端 的角度来看。因为服务器处理的是客户端请求。不是服务器发出一些可能是请求的重写 url。

标签: php apache mod-rewrite rule


【解决方案1】:
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_]+)$ index.php?paste=$1 [L]
RewriteRule ^([A-Za-z0-9-_]+)/edit$ index.php?paste=$1&page=edit [L]

例子:

  • domain.com/534 -> index.php?paste=534
  • domain.com/abc -> index.php?paste=abc
  • domain.com/abc123 -> index.php?paste=abc123
  • domain.com/534/edit -> index.php?paste=534&page=edit
  • domain.com/abc/edit -> index.php?paste=abc&page=edit
  • domain.com/abc123/edit -> index.php?paste=abc123&page=edit

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多