Blog

.htaccess Redirects for Root to WWW, Home Pages & Single Pages to Other Pages & More Examples
Posted on April 30, 2012 in .htaccess, Apache by Matt Jennings

[apache]
Options All -Indexes

# Error Documents
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php

# Turn on redirecting.
RewriteEngine on

# Redirect root to www host.
RewriteCond %{HTTP_HOST} ^[^.]+.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Redirect from explicit homepage to implicit homepage.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^/]+/)*index.(php|asp|aspx|htm|html) HTTP/
RewriteRule ^(([^/]+/)*)index.(php|asp|aspx|htm|html)$ http://%{HTTP_HOST}/$1 [R=301,L]

# Deny GoogleBot crawling by site number.
RewriteCond %{HTTP_HOST} ^site(.*).web(.*).sesameservers.com$
RewriteCond %{HTTP_USER_AGENT} ^.*Googlebot.*$ [NC]
RewriteRule ^(.*)$ – [F]

# Redirects for Home Pages
RewriteRule ^(*.)$ /index.php [R=301]
RewriteCond %{THE_REQUEST} ^.*.php
RewriteCond $1 !^/index.php/
RewriteRule ^(.*).php$ http://www.okerstromortho.com [R=301,L]

# Single Page Redirects
RewriteRule faqs.html http://www.example.com/help.php[R=301,L]
RewriteRule contact.html http://www.example.com/contact-us.php[R=301,L]
[/apache]

Leave a Reply

To Top ↑