Skip to content

Instantly share code, notes, and snippets.

@rafaysansari
Created October 10, 2015 07:52
Show Gist options
  • Select an option

  • Save rafaysansari/e0d567355dd79d7d27dd to your computer and use it in GitHub Desktop.

Select an option

Save rafaysansari/e0d567355dd79d7d27dd to your computer and use it in GitHub Desktop.
Restricting access to the WordPress login page using a specific referer URL. Code caters for redirect loops with the inclusion of error pages.
ErrorDocument 401 /your-site's-path/index.php?error=404
ErrorDocument 403 /your-site's-path/index.php?error=404
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{HTTP_REFERER} !^http://(.*)?your-site's-name.com [NC]
RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$
RewriteRule ^(.*)$ - [F]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment