Last active
December 12, 2015 05:08
-
-
Save fossil12/4719201 to your computer and use it in GitHub Desktop.
Apache: mod_rewrite if 404 redirect to archive and back (if 404 - no loop!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Redirects for 404 to www.example.com | |
# adds "?redirected" to url that www.example.com doesn't redirect back | |
# (basic idea form http://stackoverflow.com/a/11078887/286611) | |
RewriteEngine On | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule (.*) http://www.example.com/$1?redirected [R=301,L,QSA] | |
# Location of the error document | |
ErrorDocument 404 /404.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Redirects for 404 to archiv.example.com | |
# only if query "?redirected" is not in url | |
# (basic idea form http://stackoverflow.com/a/11078887/286611) | |
RewriteEngine On | |
RewriteCond %{QUERY_STRING} !redirected | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule (.*) http://archiv.example.com/$1 [R=301,L,QSA] | |
# Location of the error document | |
ErrorDocument 404 /404.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment