Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

apache - need to escape # (hash/pound) character in .htaccess rewrite rule

The question is fairly simple but I was not able to find an answer for hours now.

What I need to do is:

RewriteRule ([^#])#(.*) $1\%23$2

Which basically means I want to url escape the freaking hash sign which comes to me from an external codepiece.

backslash () does not work to escape this sign... and please don't suggest using %23 instead # because it does not work as well.

(%23 does not match a # because it simply is not == %23)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just got this working for a site following a couple of posts on this forum, I'm using a rewrite rule with NE not escape and R=301 redirect options:

RewriteRule ^galleries/([a-zA-Z0-9_-]+)$ /gallery.html#/$1 [R=301,NE,L]

This redirects all galleries/variable to /gallery.html#/variable

Edit: The important part of the rule is NE which instructs the server to parse output without escaping characters. Without this, it will try and escape the # in the rewrite rule which is what the OP is asking about.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...