RewriteRule ^(.*)$ http://www.yoursite.com
These few lines will need to be modified with your URL, obviously. What this does is tells the server that anyone coming in to yoursite.com to automatically be forwarded to a ‘different’ website, www.yoursite.com. It also tells the search engine that yoursite.com no longer exists, and that all traffic for yoursite.com should be sent to www.yoursite.com. Now the search engines will no longer see duplicate content on your ‘two sites’.
2. I’ve had this happen a few times. Sometimes clients want the site to be in ‘pure HTML’, meaning they don’t want .php extensions at the end of their pages, they want old school .htm or .html. Which is fine, except that many times we can use PHP to make life so much easier.
[cp_slide_in display=”inline” id=”cp_id_8e7bd”][/cp_slide_in]
Good news is, we can add just one line to our .htaccess file which will tell the server to treat any .htm or .html file as a .php file. Then we can put our PHP code into the .htm file, and it’ll still parse.
AddType application/x-httpd-php .php .html .htm
3. This is the big one. Mod rewrite. While I’m not going to go into this in great detail, (it deserves its own post, which plenty of others have already done), I wanted to mention that it is a great way to help in your SEO endeavors.
First, here’s the code:
RewriteRule ^member/([^/\.]+)\.html$ profile.php?u=$1 [L]
Redirect 301 profile.php?u=([^/\.]+) http://www.ourdatingsite.com/member/$1.html
In this case, what we are doing is running a dating website. The site lists people’s profiles, etc, and each profile goes to /member/profile.php?u=becky
In the search engine’s minds, this is an ugly URL. It doesn’t tell much about the member, so we’ve created this rule to make an imaginary URL just for the search engines that is much more friendly. This rule changes our path to /member/becky.html
Cool thing is, this page, becky.html doesn’t really exist on the server. It’s being faked by this rewrite. So we’ve created one PHP file (profile.php) which will handle any username that is passed to it, and the rewrite will create that fake page at username.html.