Skip to content

Instantly share code, notes, and snippets.

@codfish
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codfish/869e741b45ac95f1d1ea to your computer and use it in GitHub Desktop.
Save codfish/869e741b45ac95f1d1ea to your computer and use it in GitHub Desktop.
Scenario: You use a subdomain for your WP Admin separate from your blogs main domain, i.e. admin.superblog.com. You want to make sure only requests to the WP admin use this subdomain. This apache rewrite logic redirects all non-admin traffic away from admin domain to the homepage, keeping in mind that preview urls should also be included as an a…
RewriteEngine On
RewriteBase /
# http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
# "If you wish to match against the full URL-path in a per-directory (htaccess) RewriteRule,
# use the %{REQUEST_URI} variable in a RewriteCond."
RewriteCond %{HTTP_HOST} ^admin.superblog.com$
RewriteCond %{REQUEST_URI} !^(/wp-admin|/wp-login|/wp-content|/wp-includes)
RewriteCond %{QUERY_STRING} !^(.*?)preview=true(.*?)$
RewriteRule (.*) http://superblog.com? [R=301,L] # the trailing ? after the domain makes sure to remove any query string params from the original request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment