Welcome to 10For2 Web Development

An online presence is more than just a website; it’s the face of your company to the world. We specialize in developing that presence for small to medium size businesses.

Full Service Online Solutions

While our main focus is website design and development, we also specialize in marketing material, video production, and email and data hosting. Our goal is to become your one-stop shop for business identity solutions.

Login Panel




web development · content strategy · e-commerce wordpress · site maintenance · social media · seo

Blog Entry » January 27th, 2011

Linux 301 Redirect Code

I constantly find myself needing .htaccess code for a 301 redirect of some kind. I frequently Google to find what I need. Eventually I bookmarked a couple sites for easy access. However, I finally decided to make the information more readily available and saved a txt file in my code library. No idea why it took me so long to come up with this revolutionary idea [/sarcasm]. Anyway, I thought I’d post it here for posterity and to maybe help someone else find it and add it to their files. Feel free to copy/paste away.

REMOVE HTML EXTENSION

Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]

REMOVE PHP EXTENSION

Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]

REDIRECT WWW TO NON WWW

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example.com
RewriteRule (.*) http://example.com/$1 [R=301,L]

REDIRECT NON WWW TO WWW

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

301 REDIRECT EACH PAGE

Redirect 301 /oldpage.html http://example.com/newpage.html

Enjoy!

This entry was posted on January 27th, 2011 @ 9:50am and is filed under Blog, Code, Designer's Corner. You can follow any responses to this entry through the RSS feed. You can leave a response, or trackback from your own site.

Leave a Reply