Reputation: 4150
I want to make a proxy for external links with apache's mod_rewrite module.
I want it to redirect user from, ie http://stackoverflow.com/go/http://example.com/
to http://example.com/
where http://stackoverflow.com/
is my site's URL. So I added a rule to .htaccess
file.
RewriteRule ^/go/http://(.+) http://$1 [R=302,L]
But it doesn't work at all. How to fix this?
Upvotes: 0
Views: 65
Reputation: 1477
This will rewrite all urls (without the beginning http://) to new complete URL. If you're gonna use https links also, you need something like the second rule.
RewriteRule ^go/(.*) http://$1 [R=302,L,QSA,NE]
RewriteRule ^gos/(.*) https://$1 [R=302,L,QSA,NE]
I also added the QSA if your need to include parameters
Upvotes: 0
Reputation: 20755
I am not sure if Apache or the browser reduces //
to /
, but since it doesn't change the directory one of them reduces this to a single slash on my setup. That's why the second slash has a ?
behind it in the rule below:
RewriteRule ^go/http://?(.*)$ http://$1 [R,L]
This will redirect the user to that domain.
Upvotes: 1