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.1k views
in Technique[技术] by (71.8m points)

apache - Preserving double slashes in mod_rewrite

I have searched everywhere for this answer, and the answers that have been posted do not fit my specific situation as it gives me 404 errors, and I'm not sure why.

I am trying to rewrite this: /c.php?url=http://www.example.com

Into this: /c/http://www.example.com

Right now I have this in my mod_rewrite:

RewriteEngine on
RewriteRule ^c/(.*)(/)?$ /c.php?url=$1

But when it rewrites the url that I am trying to send into the PHP script, it writes "http:/example.com", with one slash instead of the double slash.

I've seen a lot of things posted about this involving the THE_REQUEST rule, but when I try to apply them to my htaccess file, they fail. I am not sure what is wrong, any help would be much appreciated.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Apache removes multiple slashes inside the path. And as you’re already mentioned, you can solve this by inspecting the request line in THE_REQUEST:

RewriteCond %{THE_REQUEST} ^[A-Z]+ /c/([^? ]+)/?
RewriteRule ^c/ /c.php?url=%1

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

...