htaccess [Introduction]: Rules, norms, control over your content published on the net

When we share something on the network, and I refer specifically to hosting, we need a server like Apache, Nginx, LightHTTPD, Cheroke, etc.

So, we share a folder, files and those who access our computer through their browser, will be able (using the same browser) to interact with what we have hosted, it can be a website, multimedia content, etc.

But… How can we put rules, norms of access to what we share?

There are many ways to do this, here I will talk about .htaccess.

What is htaccess?

In each folder that we have shared (hosted) we can put a file .htaccess (notice the period at the beginning of the name, this indicates that it is hidden). This file will be our police for calling it in some way, because in it we can write rules or norms that will help us to manipulate / manage access to that same folder where the file is, to the folder and files (and subfolders) that this same contain.

Simply put. If I have the folder «/test/«, Making use of a .htaccess I can configure which IPs I want to access and which not, configure if I want that when someone enters this folder it will automatically redirect them to another site, and a VERY long etc.

Let's get into the subject a bit ...

For example, we have a folder called «giant»(Without the quotes), which can be accessed through our own IP address, or through a specific domain. In other words, we can access the content of this folder through:

  1. http://10.10.0.5/dev/
  2. http://kzkggaara.net/dev/
  3. Also by http://127.0.0.1/dev/ y http://localhost/dev/

In this folder we are developing something new, working on a new project or something, and we do not want anyone else except ourselves to access, that is ... only we can enter and see the content of that folder, the rest who try to access simply will not be able to , as access will be denied.

To achieve this, we create a file .htaccess in the folder giant, and in this file we put:


order deny, allow
deny from all
allow from 127.0.0.1

Put this in the .htaccess, will deny access to any computer other than 127.0.0.1 (that is, the computer itself where Apache is installed) when you try to access the folder you will get this error:

If you want to also allow the IP 10.10.0.5 to access it, just add a line ... looking like this:


order deny, allow
deny from all
allow from 127.0.0.1
allow from 10.10.0.5

This is the essence ... the basic or the simplest could be said 🙂

I will put several tips on how to better manage our folders using .htaccessIf someone has a suggestion for a tip, question or something like that, tell me 😉

regards


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   truko22 said

    Interesting thank you very much 😀

    1.    KZKG ^ Gaara said

      Thanks for the comment 😉

      1.    Hugo said

        By the way, there is a misspelling at the beginning, it is Cherokee and not Cheeroke.

        1.    KZKG ^ Gaara said

          Ok, I'll fix it right now 😀

  2.   faustod said

    Very interesting, I hope for the following. regards

    1.    KZKG ^ Gaara said

      The next one will be redirected and that 😉 ... tomorrow I will not put it because tomorrow there are special posts for the anniversary haha

  3.   3ndriago said

    KZKG I'm waiting for your next post !!! This tea interests me a lot! If you have any links to other sources, tutorials or books please tell me so you can send them to me or tell ELAV to pass them on to me, if not, please.
    Specifically tell me if you have something on how to hide parts of a web address, for example: from http://www.loquesea.com/index.php/pagina that only shows: http://www.loquesea.com/pagina
    Thanks in advance!

    1.    KZKG ^ Gaara said

      Yes don't worry, I haven't forgotten 😉… just that I've been extremely busy since I got to the new job.
      For what you tell me, if you use PHP version greater than 5.2 put in your htaccess this:
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /index.php?/$1 [L]

      Tell me if it works for you, because I have nothing here to prove it.
      Greetings friend, THANK YOU for everything you have done for us.

      1.    Daniel ruiz said

        Sorry, will you have any examples that can access the folder where the project is stored?

        I mean that in the address bar the visitor only accesses with the domain.com
        and not with domain.com/projectfolder

  4.   Luis said

    From this thread it would be nice if you explained how to manage .htaccess to give access to folders with password.
    Others:
    - If any of you dare to post something about development IDE's
    - In the field of opinion on programming languages: Trend and evolution.
    - Linux and Android settings

  5.   Luis said

    Sorry I forgot to thank you for keeping desdelinux how you do it Congratulations.