Open the same file from several (or all) URLs

0

I have seen that many pages open the same file (for example /home/index.php ) whether you put ejemplo.com/articulo1 or ejemplo.com/articulo2 .

My goal with this is to replace the home/&var=ejemplo with home/ejemplo and from the same file read the URL and show the content I need.

What I want is to know how this can be done, I imagine that since htacces , but I have searched and in no way find anything.

  

For example, WordPress uses it, and as we know it does not create a file   for each article, but read the link and show it from the same   file through the database.

Thank you very much.

    
asked by ByBrayanYT - Tops y más 03.12.2018 в 19:34
source

1 answer

1

It's very easy to do, first create a .htaccess file with the following:

Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>

# Redirigimos todas las peticiones a excepcion de los archivos de imagenes, css y js.
RewriteEngine On
RewriteCond %{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.css|\.js)$
RewriteRule (.*)  index.php [QSA]

</IfModule>

With this, all the requests made to your domain will be redirected to the index.php file. Now it's time to get the variables you need for $_GET and $_POST . I recommend a library called Phroute to make this task easier.

Greetings!

    
answered by 03.12.2018 в 21:09