Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a few Privoxy rules, that can redirect HTTP Wikipedia [en,de] traffic to HTTPS: (a little part from the "user.action" file)

{ +redirect{s@http://en.wikipedia.org/wiki/@https://secure.wikimedia.org/wikipedia/en/wiki/@} }
.en.wikipedia.org

{ +redirect{s@http://de.wikipedia.org/wiki/@https://secure.wikimedia.org/wikipedia/de/wiki/@} }
.de.wikipedia.org

So you get the problem: is there any way to put a "regexp" or something to: "en", "de"? There are hundreds of other languages, i think it's a bad solution to write down them all.<

There is another question: is my solution good so far? I'm asking that because if i visit https://secure.wikimedia.org/wikipedia/en/wiki/File:Nokota_Horses_cropped.jpg that's ok, it's using HTTPS. BUT if i click on the picture: http://upload.wikimedia.org/wikipedia/commons/d/de/Nokota_Horses_cropped.jpg it's using HTTP! So this is not good. Are the pictures on a HTTP-only server, or i can write another redirect rule to view the pictures in HTTPS?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Privoxy's redirect action uses limited regular expressions to match and rewrite urls. Luckily, backreferences are supported. You can rewrite your redirect match in such a way to support two-letter language codes, plus the single three letter code you mentioned:

{ +redirect{s@http://(..|war).wikipedia.org/wiki/@https://secure.wikimedia.org/wikipedia/$1/wiki/@} }
.wikipedia.org

I've replaced your original two letter language code with "(..|war)". The parentheses create a backreference which can later be referred to as "$1". The two dots match any two characters. The pipe character is a logical "or" operator, making matches against strings on either side. You can use the pipe multiple times within a match group. You can use multiple backreferences in a single regex. Increment the number used to refer to the match (ie. $2, $3, etc).

The Privoxy user manual appendix describes support of regular expressions and there are more useful examples there.

For your second question, you will have to write additional redirect actions for each url you want to redirect to HTTPS. This will be cumbersome, as you will have to tune your regexps for each site's url patterns, and the site must of course offer the content over SSL also.

share|improve this answer
    
thank you, it works like a charm:) one thing: there is only 1 wikipedia site that has 3 starting letters: war.wikipedia.org so there must be a (...) - So THANK YOU!! –  LanceBaynes Mar 21 '11 at 9:00
    
but: the whole redirection doesn't work if i: pastebin.com/raw.php?i=rbZMMnZK create a rule that has: (...) in it. [because of war.wikipedia.org] –  LanceBaynes Mar 21 '11 at 9:24
    
(...) is working in my configuration on Privoxy 3.0.16. I've edited the regex in the answer to also match "war.wikipedia.org", without using (...). This is a better solution, as matching with (...) will break "www.wikipedia.org". You can extend this regex to match more subdomains by adding additional strings preceded by a pipe character: (..|war|another) –  Eli Heady Mar 22 '11 at 10:03
    
I didn't understand your last comment at first. Using three dots won't match two characters unless you make one of them optional: (...?). This will still break the www subdomain on Wikipedia though (and any other three character subdomains that don't fit the alternate HTTPS url pattern in use). –  Eli Heady Mar 22 '11 at 11:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.