Archive for the ‘.htaccess’ Category

Redirect to www. with htaccess part II

Tuesday, May 8th, 2007

There is a very handy plugin written by Mark Jaquith that allows you to redirect to www. with a convenient wordpress plugin. Many people including myself set up their blog and then realise later that it´s set up to ignore the www. Obviously, if you´re really slow (like me) you only realise once you´ve got quite a few incoming links.

Mark´s plugin ensures that your blog pages don’t lose page rank and that you will get a clean 301 redirect which is search engine friendly and will make the Googlebot rejoice.

In an earlier post I already gave you the plain .htaccess method for enforcing www.

At the moment I´m also looking into a PHP method to achieve the same goal with headers but that is still being tested. I´ll keep you posted.

P.s. When you are messing around with .htaccess and you delete your directives and the redirection still seems to persist you need to clear your browser cache! Took me a whole day to figure this out…

Making a custom 404 error page

Monday, April 16th, 2007

404 Page not Found errors will not only annoy your visitors but if you have too many they can also hurt your rankings in the search engines. With AWStats you can see where a 404 error occurs and eliminate it. If you build a custom 404 error page you can inform visitors that they page that they wanted to access doesn´t exist and give them an opportunity to return to the home page.

You need access to the .htaccess file:

In there put this line: ErrorDocument 404 /error.html

You can give this any name you like but really 404.html, notfound.html, error.html would make most sense to indicate through the url what this page is about.

Next create your error.html page with a link, your logo etc. just be creative and you will have a good chance of keeping some of those visitors on your site. If you have a search box you could include that as well and maybe a link to your sitemap. There are usually two philosophies to designing a custom 404 page. One option would be to keep the usual design and just put a 404 message in the middle column for instance. Another would be to have a different page style where you just keep your logo, a centered error message and a link back to the homepage.

Make sure that all links that you use are absolute. I.e. use something like http://www.yoursite.com/articles/index.html instead of just /articles/index.html . As your 404s may sometimes be caused from within the CGI bin or other locations relative urls spell trouble. And you don´t want to provoke 404s from within your 404 page, now do you ;-) ?

All you need to do now is to upload your .htaccess file and your error.html .

The following affordable web hosts provide a .htaccess file which you will need to setup your custom 404 error page:

Bluehost – read about bluehost´s recent upgrade
Hostgator
HostIcan
Hostmonster
-read my post “bluehost hostmonster same company” they also upgraded their plan
IPowerweb
Lunarpages
Powweb
Startlogic

More detailed reviews can be found in my cheap web hosting review articles.

Redirect to www with .htaccess

Saturday, April 14th, 2007

The prefix www in web hyperlinks is becoming obsolete but a lot of people still like using it. So in order to avoid a 404 when someone tries to type in a http://yourhomepage.com you will need to setup a redirection to http://www.yourhomepage.com in your .htaccess file. This is the code you will need to enter:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^yourhomepage.com [nc]
rewriterule ^(.*)$ http://www.yourhomepage.com/$1 [r=301,nc]

This also ensures that you don´t lose page rank through links pointing to http://yourhomepage.com instead of http://www.yourhomepage.com

Hotlinking and addon domains

Tuesday, April 3rd, 2007

If you host more than one domain on one account your hotlinking protection on the main domain can become a problem with your addon domains. The hotlink protected file types will not show up in your addon domains. I had this problem recently at bluehost and I am going to share how you can get round this problem.

First things first – how do you set up hotlinking protection. In CPanel click on the corresponding link and choose the site you want to enable it for. Next just add the excluded file types and you are done. This is the hotlinking protection for one domain but what if you have more than one domain on one account? Just enable it for all three. Doing this through CPanel can get messy so we go directly to the .htaccess in your httpdocs directory.

In there you will find code which will look something like this:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://maindomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://maindomain.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.maindomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.maindomain.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|swf|dcr|png|bmp.*)$ http://www.nytimes.com/ [R,NC]

Now to take care of more than one addon domain just insert the following. In my case I set this up for two addon domains. By the way, yes I am redirecting hot link attempts to the NYTimes. After all bandwidth thieves should stay in touch with current affairs as well ;-)

RewriteCond %{HTTP_REFERER} !^http://maindomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://maindomain.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.maindomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.maindomain.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://addondomain1.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://addondomain1.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.addondomain1.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.addondomain1.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://addondomain2.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://addondomain2.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.addondomain2.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.addondomain2.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|swf|dcr|png|bmp.*)$ http://www.nytimes.com/ [R,NC]

So what’s the fuzz about? Well, as I stated before if you just install hotlinking on your top level domain then you won’t be able to use images on the addon domains beneath it unless you activate the hotlinking protection for them as well.