Skip to content

Instantly share code, notes, and snippets.

@Andrew67
Created June 5, 2019 00:35
Show Gist options
  • Save Andrew67/5e57d2779f48c0d4410f79b754f64463 to your computer and use it in GitHub Desktop.
Save Andrew67/5e57d2779f48c0d4410f79b754f64463 to your computer and use it in GitHub Desktop.
Apache .htaccess redirection template
# Redirection template
RewriteEngine On
# HTTP Status Codes
# 301 - Moved Permanently: search engines will consider (and if needed switch to) the destination URL
# 302 - Moved Temporarily: does not cause the above. Default when no code provided after the R flag
# Unconditionally redirect all paths to the target site
RewriteRule ^/?.* https://target.example.com/ [R=301,L]
# Redirect while preserving the path and query string
# e.g. https://source.example.com/page-name?param=1 becomes https://target.example.com/page-name?param=1
# RewriteRule ^/?(.*) https://target.example.com/$1 [R=301,QSA,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment