Denis Óbukhov
Denis Óbukhov

Reputation: 4150

Apache mod_rewrite links proxy

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

Answers (2)

Bjørne Malmanger
Bjørne Malmanger

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

Sumurai8
Sumurai8

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

Related Questions