Skip to content

Instantly share code, notes, and snippets.

@jennimckinnon
Last active August 29, 2015 14:10
Show Gist options
  • Save jennimckinnon/504f60b4452da6fa963f to your computer and use it in GitHub Desktop.
Save jennimckinnon/504f60b4452da6fa963f to your computer and use it in GitHub Desktop.
Addings dynamic 301 redirects to the .htaccess file for WordPress from sub-directories to sub-domains
# You need the following line before the redirects for this to work
RewriteEngine On
# 301 Redirect to subdomain no query strings attached to the end of the redirected URL
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^page_id=10$ [NC]
RewriteRule ^site1/$ http://site1.yourdomain.com/newpage? [R=301,NE,NC,L]
# 301 Redirect to subdomain with query strings attached to the end of the redirected URL
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^page_id=10(&.*)?$ [NC]
RewriteRule ^site1/$ http://site1.yourdomain.com/newpage?%1 [R=301,NE,NC,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment