Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx rewrite for changing /wp-login.php to /login #4

Open
JasmineAhmed opened this issue Oct 2, 2012 · 7 comments
Open

Nginx rewrite for changing /wp-login.php to /login #4

JasmineAhmed opened this issue Oct 2, 2012 · 7 comments

Comments

@JasmineAhmed
Copy link

Hi Perusio,

Firstly, thank you for the config. Not really an issue but was wondering what the nginx equivalent of the apache rewrite is -

RewriteRule ^login$ http://YOUR_SITE.com/wp-login.php [NC,L]

Thanks for the help

Jasmine

@perusio
Copy link
Owner

perusio commented Oct 2, 2012

On 2 Out 2012 15h38 CEST, [email protected] wrote:

Hello Jasmine,

Hi Perusio,

Firstly, thank you for the config. Not really an issue but was
wondering what the nginx equivalent of the apache rewrite is -

RewriteRule ^login$ http://YOUR_SITE.com/wp-login.php [NC,L]

You can hide the wp-login.php file in order to block direct access:

location ^~ /login {
    try_files /wp-login.php /index.php?q=$uri&$args =404;
 }

location ~ ^(?<script>wp-login\.php)(?<path_info>.*)$ {
    internal; # block direct access if you want.
    include fastcgi.conf;
    ## The fastcgi_params must be redefined from the ones
    ## given in fastcgi.conf. No longer standard names
    ## but arbitrary: named patterns in regex.
    fastcgi_param SCRIPT_FILENAME $document_root$script;
    fastcgi_param SCRIPT_NAME $script;
    fastcgi_param PATH_INFO $path_info;
    ## Passing the request upstream to the FastCGI
    ## listener.
    fastcgi_pass phpcgi;
}

You can omit the previous location block if you don't want to block
direct access to wp-login.php.

--- appa

@JasmineAhmed
Copy link
Author

Thanks Perusio. I do not want to hide wp-login.php file. My client doesnt want authenticated users on his website knowing that its a wordpress site, hence why i need to rewrite the url to /login and not /wp-login.php

@perusio
Copy link
Owner

perusio commented Oct 2, 2012

The mod_rewrite rule, rewrites /login to http://YOUR_SITE//wp-login.php. Is YOUR_SITE the same site or another one? If it's another one, it's simpler:

location ^~ /login {
    return 301 http://YOUR_SITE/wp-login.php;
} 

@JasmineAhmed
Copy link
Author

it is the same site. I'm guessing the solution to my clients problem would be -

location ^~ /wp-login.php {
return 301 http://YOUR_SITE/login;
}

@perusio
Copy link
Owner

perusio commented Oct 2, 2012

Yep. That's it. If you want just a 302 redirect omit the 301.

location ^~ /wp-login.php {
    return http://YOUR_SITE/login;
}

@JasmineAhmed
Copy link
Author

thank you very much Perusio, i will try that.

@rajuginne
Copy link

renaming wp-login.php by redirect
blocking direct access to wp-login.php

rewrite rule not working for multiple websites

please help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants