Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
977 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.7k users

...