1

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.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
boomboom
  • 11
  • 2

1 Answers1

2

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
Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • Thanks, Gumbo. I had to add a + in the /c/([^?\ ]+)/? to allow more than one character, but it works well, though I am new to mod_rewrite and I am having a difficult time trying decipher how the THE_REQUEST command works... Also, is there any way to preserve question marks in the URL that is being sent as well? Thanks! – boomboom Nov 08 '10 at 00:41
  • @boomboom: *THE\_REQUEST* represents the [request line](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1). And if you want to get the full requested path and query string, it is probably easier to get it in *c.php* from `$_SERVER['REQUEST_URI']` directly. – Gumbo Nov 08 '10 at 06:39