代码之家  ›  专栏  ›  技术社区  ›  janpio WillBroadbent

如何重写包含%23的URL?

  •  5
  • janpio WillBroadbent  · 技术社区  · 16 年前

    我有一个(wordpress)博客,用户在评论后会被重定向回带有他们评论锚的页面。应该是这样的:

    http://example.org/foo-bar/#comment-570630

    但不知怎么的,我的日志文件中有很多404,比如:

    http://example.org/foo-bar/%23comment-570630

    有没有办法写一个.htaccess重写规则来解决这个问题?

    2 回复  |  直到 16 年前
        1
  •  5
  •   Tate Johnson    16 年前

    %23 # . 我怀疑你的重写规则不能满足你的要求 %23

    但是,可以用重写规则来解决您的问题。请理解,在提交评论后,您将向客户返回两个响应。这就是为什么最好纠正第一个回答。

    # http://example.org/foo-bar/%23comment-570630 -> http://example.org/foo-bar/#comment-570630
    RewriteCond %{REQUEST_URI} %23comment-\d+$
    RewriteRule (.+)\/%23-comment(\d+)$ http://host/$1/#comment-$2 [R=301]
    

    这是未经测试,但应该工作(我不确定是否逃脱) \%

        2
  •  0
  •   maddrag0n    13 年前

    B Flag ?

    RewriteCond %{REQUEST_URI} %23comment-\d+$
    RewriteRule (.+)\/%23-comment(\d+)$ http://host/$1/#comment-$2 [B,R=301]