Very Recent Posts

Sunday, January 24, 2016

htaccess Redirect to Maintenance Page

htaccess Redirect to Maintenance Page

Redirecting visitors to a maintenance page or other temporary page is an essential tool to have in your tool belt. Using HTAccess, redirecting visitors to a temporary maintenance page is simple and effective. All you need to redirect your visitors is the following code placed in your site’s root HTAccess:
# MAINTENANCE-PAGE REDIRECT
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
 RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
 RewriteRule .* /maintenance.html [R=302,L]
</IfModule> 

That is the official copy-&-paste goodness right there. Just grab, gulp and go. Of course, there are a few more details for those who may be unfamiliar with the process. Let’s look at all the gory details..

Redirecting Traffic with HTAccess

To redirect your visitors to a maintenance page, place the previous code into an HTAccess file located in your site’s root directory. This will ensure that all pages and resources contained within your domain will be redirected for visitors. Thus, if you would like to redirect only requests for a specific subdirectory within your domain, the .htaccess file containing these rules would be placed in that directory (instead of root).
Now that the HTAccess is in place, you’ll need to create and upload your maintenance page, named “maintenance.html”, to the root directory of your site. This file can be just about anything, and does not need to be written in HTML. You can use, say, PHP to make it all dynamic, but remember to change the two instances of the file name in the HTAccess code to match the actual name of your file.

Code Explanation

  1. The first line is merely a comment to explain the purpose of the code. It is not processed by the server.
  2. The second line enables Apache’s rewrite engine, mod_rewrite. Depending on your server setup, this line may be unnecessary.
  3. The third line checks to see if the request is coming from your computer. If it is, then the redirect does not happen. For this to work, you need to change the numbers in this line to match your own IP address.
  4. The fourth line prevents an infinite-loop scenario by testing the request against the name of your maintenance page. Obviously, we don’t want to redirect requests for the page to which we are redirecting.
  5. The fifth and final line contains the action. It basically redirects all requests that meet both of the previous rewrite conditions to the specified maintenance page. Apache doesn’t allow us to use 500-level response codes, so we are stuck with the next best thing, a 302 – temporary – response.

Update: Multiple IP Addresses

It was asked in the comments how this might work when you want to allow multiple IP addresses. There are basically two ways. First, you can add more RewriteConds to the previous code, like so:

# MAINTENANCE-PAGE REDIRECT
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
 RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
 RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
 RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
 RewriteRule .* /maintenance.html [R=302,L]
</IfModule>
 With this method, edit each IP address to match your own, and add/remove as many IPs as needed. The second method is equally effective, and looks like this:
<Limit GET POST PUT>
 Order Deny,Allow
 Deny from all
 Allow from 123.456.789.000
 Allow from 123.456.789.000
</Limit>
ErrorDocument 403 /maintenance.html
<Files maintenance.html>
 Order Allow,Deny
 Allow from all
</Files>

This method is a bit simpler, but not as good for SEO should the search engines visit while in maintenance mode. The first method sends a 302 - Moved temporarily status code, while the second sends a less accurate 403 - Forbidden status code. Even so, should you go with method #2, edit the IPs to those of your own, adding or removing new lines as needed for site access.

It’s like a Pandora’s Box..

It’s difficult to keep posts short and sweet when working with HTAccess techniques. There is justso much that you can do with it. For example, we can do htaccess password-protection, allow access to multiple visitors, request specific redirects, and much more. But I refrained from complicating things in an effort to keep this post focused and on-topic. Nonetheless, there is always room for improvement, so if you see something that could make this simple HTAccess-redirect technique even better, then please share via the comments. Thanks!

Saturday, December 5, 2015

FORCE FILE DOWNLOADS ON YOUR SITE

FORCE FILE DOWNLOADS ON YOUR SITE

Today I was browsing some Nigerian websites looking for songs to download (yeah, downloading isn’t illegal in Nigeria), and I happened to notice something. For some reason, every time i hit the download button, I usually end up with the song playing directly on my device without downloading to my sound system. Its annoying.
It also applies to documents like pdf files, where the document starts loading with the browser instead of downloading to my computer.

How to force file download

There is a way you can force the browser to acknowledge that it needs to download (not stream)  the file in question. First, you need to make a few changes to your websites files. This is not going to be easy if you are not a programmer of have some sort of web knowledge.
For clarity purposes, I’ll use the popular cPanel, as a backbone for the screen shots i’ll provide.

Step 1

Log into your website using FTP (File Transfer Protocol). In a lay mans words, log into the part of your website that lists all the file in your domain.  When you have logged in, you should see your list of files.
Now, navigate to your “public_html” folder. This should be the folder where your actual web files reside, your web root if you may. If you’re using cPanel, just log into your cPanel, then click on the “File Manager” link in your cPanel.
 Now make sure you select the following on the pop up that comes after clicking the file manager link. Select “Show Document root for:” then choose the website inquisition from the dropdown field. Also check the “show hidden files” selection, click OK.

Step 2

Now, look for a file called “.htaccess” in your file list. Select it and click “Edit” on the top tool bar. If you do not have this file, click on “New File” and make a new file called “.htaccess” (without quotes and without a file name, just .htaccess).
In the file add this block of code to the very bottom (make sure its the last thing written at the bottom):
<FilesMatch "\.(mov|mp3|mp4|wav|pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>
 Now save the file. That’s all. Any files like mp3, mov, mp4, wav, and pdf, will be downloaded directly to the browser instead of opening in the browser. You can add more file types if you feel the need to. Just add a pipe character and the file extension to the end of the list of file extensions. Example, to add direct download for jpeg files, change
<FilesMatch "\.(mov|mp3|mp4|wav|pdf)$">
 to
<FilesMatch "\.(mov|mp3|mp4|wav|pdf|jpg)$">
 Hope this helps someone in the future.

Friday, August 14, 2015

FREE HOSTING OR PAID HOSTING – WHICH ONE SHOULD I USE FOR MY WEBSITE?

FREE HOSTING OR PAID HOSTING – WHICH ONE SHOULD I USE FOR MY WEBSITE?

FREE HOSTING VS PAID HOSTING – INTRO

Setting up a new blog is hard, but what is even harder is investing your precious $50 in some paid hosting, when you can just use that awesome free hosting company that told you there would be no ads and unlimited bandwidth! (Read the fine print – If you use too much resources you get banned!) Have you ever wondered whether you should use paid hosting or free hosting for your new blog? Free hosting vs paid hosting, and paid hosting always have more advantages than disadvantages!

1. MORE BANDWIDTH AND DISK SPACE

If your site starts to attract more visitors, your free hosting bandwidth will run out, and your visitors won’t be able to access your website! Most free hosts offer a tiny amount of disk space and store your websites with a few hundred other ones on one weak server. This is one part in free hosting vs paid hosting where paid hosting is definitely better.

2. THEY MAKE MONEY FROM YOUR SITE

Many free hosts put all kind of ads on your website, from pop unders (those are extremely annoying) to a tiny sign saying “free hosting by xxxhost”on the bottom of your page. That looks extremely unprofessional, and makes visitors less likely to enjoy and trust your site! The worst kind is those who promise you lots of bandwidth and disk space, so you happily setup your blog, only to find out they had put ugly banners all around it!  Free hosting vs paid hosting – Paid Hosting wins again! Free hosting may save you some money in the short term, but for the long term, it makes you lose money by scaring away visitors and reducing your traffic, therefore your revenue!

3. UNRELIABLE

Free hosts are really unreliable! I used to host a few sites on a free host a year ago, and one day, the free host just shut down, and I lost my website. And since it was a free host, there wasn’t any backup, so I couldn’t retrieve it! So if you’re just starting your new blog, put hundreds of hours worth of work into it, finally managed to let it get to the front page of Google, and just started to earn a buck or two each day from Adsense, and suddenly, Oops! Your free host shut down and you lost all your traffic, income, and time! What a disaster! Free hosting vs paid hosting – wow, free hosting loses again! The best way to solve that, is to use a paid host. Indeed, some of them are quite cheap, at less than $25 a year!

FREE HOSTING VS PAID HOSTING – VERDICT

When you compare free hosting vs paid hosting, paid hosting is always better. There’s this saying –“There’s no Free Lunch”, and it applies to the hosting industry too. If a host offers a free service, theremust be a catch of some kind, maybe some ads, slow load times, unreliable services, etc. You’re better off using a paid host!
Enjoy!
Feel free to like, share, and tweet! If you have any questions, comment below, and I promise that I’ll respond to every and all comments!


3 VERY COMMON WORDPRESS MISTAKES AND HOW TO AVOID THEM

3 VERY COMMON WORDPRESS MISTAKES AND HOW TO AVOID THEM

THREE TOTALLY AVOIDABLE COMMON WORDPRESS MISTAKES

WordPress is the world’s leading Content Management System, and it’s easy to see why. The software is pretty intuitive when it comes to adding simple content like articles or images, so just about anyone can learn to navigate the basics.
However, there are some pretty common WordPress mistakes to be had when it comes to setting things up and keeping them running smoothly. Below is a list of 3 common mistakes that people make with WordPress and steps you can take to fix them.

COMMON WORDPRESS MISTAKES NUMBER 1: HAVING ‘ADMIN‘ AS YOUR USERNAME



When you install WordPress in your Control Panel (usually done via the Quick Install option), you have the option to setupyour own Username that you will use to log in to your WordPress Dashboard. When setting up their site, many do not enter a personalized username and by default, they‘re assigned the username of ‘admin‘. This may not seem like a big deal, but actually, it sort of is. Why?
Well, consider this. Your WordPress Login Area, is essentially the lock to the back door to your site and your login credentials are the key to unlocking it. By choosing a personalized username, you create a unique key to opening your site that no one else has. But, when you choose the default option of ‘admin‘, you are pretty much leaving your “backdoor” unlocked. It’s like a welcome mat for hackers…
Many don’t think that getting hacked will happen to them, but it happens all the time. One way to beef up security and help prevent this is by choosing a unique username when you install WordPress.
If you have already set up your site with the ‘admin‘ username and have had your site up for a bit, there is actually a way that you can go in and change it without the need to reset your entire site. If that seems like your best option, just follow this tutorial by WPBegginer:
  • How To Change WordPress Username – LINK

COMMON WORDPRESS MISTAKES NUMBER 2: NOT ADDING A DESCRIPTION FOR CATEGORIES

This is another point that may seem superfluous, but it’s really not. Why?
Because adding descriptions to your categories is actually a good SEO practice. By adding these, you are helping to define the keywords that you’re likely using for your categories and when you do that, you have a chance at better ranking. Some may argue that this isn’t needed, but it won’t hurt either.
To add a description to your categories, go to your Dashboard, scroll over Posts and then click on Categories in the pop out. Once you’re there, scroll over your Category, click edit and then, add your description.
It’s that simple!

COMMON WORDPRESS MISTAKES NUMBER 3: NOT CREATING A BACKUP OF YOUR SITE

This is one of the biggest mistakes I see people make with WordPress and I cringe when I do. If you’re going to take anything away from this article, please let it be this.
Create. A. Backup. Today.
I cannot emphasize the importance of this enough. Could you imagine if all your hard work, all that money you put into your site, all the money it makes you, was gone? There is a lot out there that can cause your site to go haywire, and even simple updates to WordPress or Themes can wipe your site clean! Backups are there for just that scenario.
There are both free and paid plugins that can help in creating a full file backup (this is the kind of backup I highly recommend). My absolute favorite for creating quick and scheduled backups is ManageWP  and I can say it’s my favorite because I use it. Others prefer BackUp Buddy or go for a free plugin like WordPress To DropBox to do the job. No matter which option you pick, just be sure to pick one. One day, you’ll be so thankful you did. I promise you that.
That wraps my top 3 Common WordPress Mistakes. Do you guys have any suggestions that you think should be at the top of that list? If so, be sure to comment below. I would love to hear your input.