views:

33

answers:

1

I'm trying to create a rewrite rule that will do the following:

http://www.example.com/http://other.example.comhttp://www.example.com/index.php?var=http://google.com

This is my current rule:

RewriteCond %{REQUEST_URI} ^/(http[s]?\:\/\/|ftp\:\/\/)?(www\.)?[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov|ws|info)$
RewriteRule ^(.*)$ http://www.example.com/index.php?var=$1 [R]

Which produces:

http://www.example.com/http://google.comhttp://www.example.com/index.php?var=http:/google.com

No matter what I try, I'm always getting http:/ out, instead of http://. Any ideas?

A: 

Apache removes empty path segments like the one in http://. So /foo//bar/// is interpreted like /foo/bar/. But the original request line in THE_REQUEST remains unchanged:

RewriteCond %{THE_REQUEST} ^GET\ /(https?://[^\ ]+)
RewriteRule ^https?:/ /index.php?var=%1 [R]
Gumbo
Excellent! This was exactly what I needed. But now I've got another question...Is it possible to do this same procedure without doing a [R]. Ideally, I'd like the actual address in the address bar to remain as http://domain.com/http://google.comI've tried the [L] and [PT] flags w/o success. I get server errors.Thank you!!
paperreduction
@paperreduction: Just leave the *R* flag away and it should work.
Gumbo
@Gumbo: Thanks, but I suspect I've got conflicting redirect rules (doing a www R301 also). So leaving the [R] off still resulted in a server error. I'll figure it out though. The empty path explanation solved a lot of my problems.
paperreduction
@paperreduction: You should put those rules that cause an external redirect before those rules that just cause an internal redirect. So in this case put my proposed rule after your 301 rules.
Gumbo