如何改写为%23中有一个网址是什么? [英] How to rewrite a URL with %23 in it?

查看:270
本文介绍了如何改写为%23中有一个网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个(字preSS)的博客里评论的用户后重定向回页面的锚他们的意见。应该是这样的:

I have a (wordpress) blog where after commenting the users are redirected back to the page with an anchor to their comment. Should look like this:

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

但不知何故,我得到了很多的404 INS我的日志文件这样的网址:

But somehow I get a lot of 404 ins my logfiles for such URLs:

<一个href="http://example.org/foo-bar/%23comment-570630">http://example.org/foo-bar/%23comment-570630

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

Is there a way to write a .htaccess rewrite rule to fix this?

奖金的问题: 任何想法,为什么出现这种情况和我能做些什么呢?

Bonus question: Any idea why this happens and what I can do about it?

推荐答案

%23 的URL连接codeD重新$ P $的psentation 。我怀疑你的重写规则将无法满足 23%。你应该研究如何应对正在紧张施工。具体而言,任何URL编码功能。

%23 is the URL encoded representation of #. I suspect your rewrite rules will not satisfy %23. You ought to investigate how the response is being constructed. Specifically, any URL encoding functions.

不过,这将有可能与一个重写规则来解决你的问题。要知道,你会返回两个响应到客户端后评论被提交。这就是为什么它是preferable纠正的第一反应。

However, it would be possible to solve your issue with a rewrite rule. Understand that you'll be returning two responses to the client after a comment is submitted. This is why it is preferable to correct the first response.

# 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]

这是未经测试,但应该工作(我不确定逃逸 \%,因为它在mod_rewrite的特殊含义)。

It's untested, but should work (I'm unsure about escaping \% as it has special meaning in mod_rewrite).

这篇关于如何改写为%23中有一个网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆