# Dokuwiki SSL Login rewrite rules

**URL:** <https://www.ruby-forum.com/t/dokuwiki-ssl-login-rewrite-rules/208454>\
**Category:** NGINX\
**Created:** [June 18, 2011, 8:16pm UTC](https://www.ruby-forum.com/t/dokuwiki-ssl-login-rewrite-rules/208454 "2011-06-18T20:16:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [June 18, 2011, 8:16pm UTC](https://www.ruby-forum.com/t/dokuwiki-ssl-login-rewrite-rules/208454/1 "2011-06-18T20:16:08Z")

</div>

Dear all,

I’m preparing a nginx configuration for Dokuwiki and it all works except  
the following feature:

If a user logs in the protocol force-switches to https and back to plain  
http after the login. So far, this has been realised with the apache2  
rewrite rules which I stole from [1].

Can anybody, who is familiar with nginx rewrite rules translate these  
apache2 rules to nginx? I’m sure many users would benefit from this.  
Thank you very much in advance. I hope this is even possible with nginx  
:S

[1] [tips:httpslogin [DokuWiki]](http://www.dokuwiki.org/tips:httpslogin?s%5B%5D=ssl&s%5B%5D=rewrite)

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 20, 2011, 6:33pm UTC](https://www.ruby-forum.com/t/dokuwiki-ssl-login-rewrite-rules/208454/2 "2011-06-20T18:33:57Z")

</div>

Okay, I started to translate the rule myself and after a bit of  
experimentation I ended up with this. The aim is to force users to use  
the https protocol for login and administration.

# in context server:

if ($args ~ do=(login|admin|profile)){  
rewrite ^ https://$server\_name$uri redirect;  
}

While this works for Opera, it doesn’t work for wget and Firefox:  
There’s obviously a redirection loop going on:

% wget --no-check-certificate [http://xvt.localhost/start\?do=login](http://xvt.localhost/start%5C?do=login)  
–2011-06-20 18:25:57-- [http://xvt.localhost/start?do=login](http://xvt.localhost/start?do=login)  
Resolving xvt.localhost… 127.0.1.1  
Connecting to xvt.localhost|127.0.1.1|:80… connected.

HTTP request sent, awaiting response… 302 Moved Temporarily  
Location: [https://xvt.localhost/start?do=login](https://xvt.localhost/start?do=login) [following]  
–2011-06-20 18:25:57-- [https://xvt.localhost/start?do=login](https://xvt.localhost/start?do=login)  
Connecting to xvt.localhost|127.0.1.1|:443… connected.

HTTP request sent, awaiting response… 302 Moved Temporarily  
Location: [https://xvt.localhost/start?do=login](https://xvt.localhost/start?do=login) [following]  
–2011-06-20 18:25:57-- [https://xvt.localhost/start?do=login](https://xvt.localhost/start?do=login)  
Reusing existing connection to xvt.localhost:443.

[… and on and on… until finally]

20 redirections exceeded.

In Firefox the message looks like this:  
“Firefox has detected that the server is redirecting the request for  
this address in a way that will never complete.”

Any ideas on this?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 21, 2011, 4:19am UTC](https://www.ruby-forum.com/t/dokuwiki-ssl-login-rewrite-rules/208454/3 "2011-06-21T04:19:53Z")

</div>

On 20 Jun 2011 17h33 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Okay, I started to translate the rule myself and after a bit of  
> experimentation I ended up with this. The aim is to force users to  
> use the https protocol for login and administration.

What is written on the wiki page you referred:

[http://www.dokuwiki.org/tips:httpslogin?s](http://www.dokuwiki.org/tips:httpslogin?s)

below the Apache mod\_rewrite rules should do the trick. You can  
replace the conditions for the query string args by:

## On the http server block.

if ($arg\_do ~\* (?:log|admin|profile)) {  
rewrite ^ https://$host$request\_uri? redirect;  
}

## On the https server block.

if ($arg\_do = show) {  
rewrite ^ http://$host$request\_uri? redirect;  
}

if ($arg\_do = “”) {  
rewrite ^ http://$host$request\_uri? redirect;  
}

— appa

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 21, 2011, 2:57pm UTC](https://www.ruby-forum.com/t/dokuwiki-ssl-login-rewrite-rules/208454/4 "2011-06-21T14:57:28Z")

</div>

Yes, with the help from people on #nginx (thanks again kolbyjack), I was  
able to get it to run, so I already added the working configuration  
snippet to the Dokuwiki [1]

I hope I didn’t cause you too much work, Antnio P. P. Almeida.

nginx is great software and I’m very happy now. The only drawback is  
that it doesn’t fully support WebDAV (git-http-push not working) but  
that is another topic. Thanks for you help, all!

[1] [tips:httpslogin [DokuWiki]](http://www.dokuwiki.org/tips:httpslogin#nginx)
