Skip to content

Instantly share code, notes, and snippets.

@blastseld
Created September 14, 2013 10:51
Show Gist options
  • Save blastseld/6561007 to your computer and use it in GitHub Desktop.
Save blastseld/6561007 to your computer and use it in GitHub Desktop.
Apache 301 SEO redirect of domain, subdomain, tld, naked domain.
# Example of working basic configuration
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName www.villapiaeventi.it
DocumentRoot /var/www/villapiaeventi.it
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/villapiaeventi.it>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
# Specific redirect, only one hop, no chained 301 redirect
<VirtualHost *:80>
ServerName villapiaeventi.it
ServerAlias *.villapiaeventi.it villapiaeventi.com *.villapiaeventi.com
RedirectPermanent / http://www.villapiaeventi.it/
</VirtualHost>
# General redirect for naked domain
<VirtualHost *:80>
ServerName default
ServerAlias *
<IfModule mod_rewrite.c>
RewriteEngine on
# WITH 'www.'
RewriteCond %{HTTP_HOST} !^www.(.*) [nocase]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}$1 [redirect=permanent,nocase,last]
</IfModule>
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment