Tag: .htaccess

  • Password Protect a Website or Sub-directory: Steps

    Password Protect a Website or Sub-directory: Steps

    Recently I was setting up a back-end admin page for a site and I wanted it to be only accessible by admins. So I came across an article by Chris Coyier on css-tricks.com. But the article was for advanced users. A newbie like me will end up getting errors. I ended up getting 500 Server error and after hours of Googling I was able to set it up properly. Follow the steps below and you will be able to password protect a website or sub-directory in no time.

    Steps:

    Creating .htaccess and .htpasswd files

    Visit http://www.tools.dynamicdrive.com/password/ to generate the contents for your .htaccess and .htpasswd files. It’s a free online .htaccess Password Generator.

    password protect website

    1. Enter usernames, one per line
    2. Enter passwords for the usernames on the left
    3. Enter filepath where you will be storing your .htpasswd (If you don’t know the filepath, read the end of the article).
    4. Submit

    After submitting you will get a page with your .htaccess and .htpasswd codes.

    htacces password generator

    Create 2 files .htaccess and .htpasswd in the file directory you want to protect and copy paste the codes from the above site to the respective file.

    htaccess location for password protection

    Finding the path of of the folder where you will be storing your password file (.htpasswd)

    This is for people who don’t know the full path of your site directory.

    Visit http://www.htaccesstools.com/articles/full-path-to-file-using-php/ and follow the instructions to find your full path of your site directory.

    I have tried to keep the steps as simple as possible. If you run into some error, let me know through the comments and I will help you sort it out.

  • Give Primary Domain a folder for Hostgator Server (Change Main Domain root Directory)

    Give Primary Domain a folder for Hostgator Server (Change Main Domain root Directory)

    It’s been a while since my last article. Was busy moving sites to Hostgator.

    In this article I will explain how to give primary domain a folder for Hostgator Server. In simple words, we will change the primary domain folder from root to another folder of our choice. This will work with most of the hosting companies.

    This will help us to have a clean root folder in the server.

    All you have to do is copy paste the following line to your. htaccess file.

    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)$ /[highlight]yourfoldername[/highlight]/$1

    Change [highlight]yourfoldername[/highlight] to the name of the folder where you want to forward your primary domain.

    If you get a 500 error or any other server error, remove all the lines from your. htaccess and just use the above code. Keep a backup of the. htaccess before deleting the lines.