Skip to content

Instantly share code, notes, and snippets.

@noyb34
Created April 17, 2013 00:54
Show Gist options
  • Save noyb34/5400931 to your computer and use it in GitHub Desktop.
Save noyb34/5400931 to your computer and use it in GitHub Desktop.
Wordpress Cannonical Snippets
# CANONICALIZATION SNIPPETS
<IfModule mod_alias.c>
# redirect empty tag requests to homepage
RedirectMatch 301 ^/tag/?$ http://example.com/
# redirect empty page requests to homepage
RedirectMatch 301 ^/page/?$ http://example.com/
# redirect empty search requests to homepage
RedirectMatch 301 ^/search/?$ http://example.com/
# redirect empty category requests to homepage
RedirectMatch 301 ^/category/?$ http://example.com/
# redirect subdirectory to homepage
RedirectMatch 301 /wp/?$ http://example.com/
# redirect favicon requests to the actual favicon
RedirectMatch 301 ^/favicon\.(?!ico) http://example.com/favicon.ico
RedirectMatch 301 (?<!(^/))favicon\. http://example.com/favicon.ico
# redirect apple-icon requests to the actual icon
RedirectMatch 301 /apple-touch-icon(.*)?.png http://example.com/apple.png
# redirect requests for humans.txt and robots.txt to the actual file
RedirectMatch 301 (?<!(^/))(humans|robots)\.txt http://example.com/$2.txt
# redirect requests for xmlrpc.php to the actual file
RedirectMatch 301 (?<!(^(/wp/)))(xmlrpc)\.php http://example.com/wp/xmlrpc.php
# redirect requests for the wp-login.php file to the login page
RedirectMatch 301 (?<!(^(/wp/)))(wp-login)\.php http://example.com/wp/wp-login.php
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment