Skip to content

Instantly share code, notes, and snippets.

@jennimckinnon
Created November 25, 2014 00:40
Show Gist options
  • Save jennimckinnon/1a1027ecb1fcac81ee25 to your computer and use it in GitHub Desktop.
Save jennimckinnon/1a1027ecb1fcac81ee25 to your computer and use it in GitHub Desktop.
Addings dynamic 301 redirects to the .htaccess file for WordPress from sub-domains to sub-directories.
# You need the following line before the redirects for this to work
RewriteEngine On
# 301 Redirect to subdirectory no query strings attached to the end of the redirected URL
RewriteCond %{HTTP_HOST} ^site2\.yourdomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^page_id=20$ [NC]
RewriteRule ^$ http://www.yourdomain.com/site2/newpage? [R=301,NE,NC,L]
# 301 Redirect to subdirectory with query strings attached to the end of the redirected URL
RewriteCond %{HTTP_HOST} ^site2\.yourdomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^page_id=20(&.*)?$ [NC]
RewriteRule ^$ http://www.yourdomain.com/site2/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