Mask Urls


I'm starting in the world and I've been trying to do several things with my Urls for several weeks:

1st Remove extension from my home page index.php

link index.php

2nd remove the .html and .php

There is a lot of info on the web and more than clarifying I made a mess.

I specify that yes I have managed to clean them by renaming this I do not know very well what it is but I think that is where the calls are made (the header menu of each page or something like that):

  • Home
  • Services
  • ....

    I simply remove the extension .php and .html to all the files and with a directive in the .htaccess so that I can recognize the urls without these extensions, it allows me to do so.

    But I waste too much time touching all the code of each of the pages continuously ... I need a universal rule that prevents me from doing this in the file. I clarify that I use a wysiwyg type editor and that when I make any changes and upload the files, I upload it with the .php and .html extensions (and once I upload them to the server I have to modify them right there).

    My question is: Is there some code for the htcaccess to hide any index.php from the home page and any file extension .php or .html from any web that I host in my public_html? Something like a general guideline.

    Guys I need help, I'm a long-term unemployed with family and I'm fighting like a big belly cat to get out of the crisos, so I'm learning on my own because I have no money to pay for any course or any programmer. If someone can help me, I will greatly appreciate it (because something else I do not have). Many thanks in advance to anyone who offers his hand.

  • asked by Santiago 29.10.2016 в 20:06

    1 answer


    If you are starting, the use of "pretty-urls" is complicated, what I will show you next will need to be polished to be 100% functional and also adapt it to your needs.

    Ideally, your entire website uploads from index.php and it is this that is responsible for "include" the content that will be displayed in the site. There are frameworks that do all this for you as laravel or codeigniter.

    The first thing is to redirect all the requests to index.php, this we do with these lines of code in .htaccess we will also indicate to which section the user wants to access, to be able to use it later from PHP, to do that we will use "$ _GET ".


    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php?action=$1 [QSA,L]

    The next thing is to distribute those requests according to what the user requires. Create a folder called content and enter your files there, for example:

    • content / contacto.php
    • content / products.php
    • content / who-are.php
    • content / principal.php


    //En la variable $action almacenamos el apartado que debemos mostrar.
    $action = $_GET['action'];
    //Si el usuario no introduce ninguna acción (apartado), se mostrará la página principal.
    $action = 'principal';
    //Comprobamos si el archivo a mostrar existe.
    //Incluimos dicha página
        require 'contenido/'.$action.'.php';

    As I said before, this code is not 100% ideal, but it is the basis of everything. You can research more about frameworks in php and about the MVC model. I wish you luck with your projects:).

    answered by 29.10.2016 в 22:37