Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My current situation right now is that I can't figure out how to make the right redirect rules in "location" My ssl.conf is as follows:

     location ~ /wp-(admin|login|includes|content)/($|.*\.php) {
           rewrite ^ https://mysite.com$uri permanent;
       }
   location / {
         return 301 http://$host$request_uri;
    }

I also have define('FORCE_SSL_ADMIN', true); defined in my wordpress config file.

When I click login, the page will go into a redirect loop with example.com/wp-admin/ . If I add index.php afterwards, the page loads fine. What do I change to make sure I'm not stuck with a redirect loop?

share|improve this question
add comment

1 Answer

You probably want separate server blocks. Having the rewrites in the same server block will just bounce you back and forth.

This is just off the top of my head, so may not be 100% correct.

server {
    listen *:80;
    server_name mysite.com;
    root /var/www/wordpress;
    access_log /var/log/acces.log;
    index index.php;
    location / {
        try_files $uri $uri/ @rewritewordpress;
    }
    location ~ /wp-(?:admin|login) {
        return 301 https://$host$request_uri;
    }
    location ~ \.php$ {
        try_files $uri $uri/ /index.php?$args;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    location @rewritewordpress {
        rewrite ^/(.*)$ /index.php?q=$1&$args;
    }
}
server {
    listen *:443;
    server_name mysite.com;
    root /var/www/wordpress;
    access_log /var/log/ssl.access.log;
    index index.php;
    location / {
        return 301 http://$host$request_uri;
    }
    location ~ /wp-(admin|login|includes|content) {
        try_files $uri $uri/ @rewritewordpress;
    }
    location ~ \.php$ {
        try_files $uri $uri/ /index.php?$args;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param HTTPS on;
    }
    location @rewritewordpress {
        rewrite ^/(.*)$ /index.php?q=$1&$args;
    }
}
share|improve this answer
    
The code fixes my redirect loop issues, however, there is trouble with the location rewrites not redirecting if I'm anywhere outside of the admin or login panel (wp-admin) (wp-login). The site should redirect users off off HTTPS if not in those two panels and if they are in them, redirect to https –  CyberguySean Jun 7 '13 at 1:48
    
Conf updated to redirect out of SSL when needed. –  chrskly Jun 7 '13 at 22:07
add comment

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.