How to change the way GET variables are used in php

I do not like something like this: example.com/?id=2222. How to change it to example.com/2222?

+3
source share
3 answers

You need to look at mod_rewrite .

From the documentation: This module uses a rule-based rewrite mechanism (based on a regular expression analyzer) to rewrite requested URLs on the fly.

Thus, the URL may look like example.com/2222 to the user, but then translated to example.com/?id=2222 on the server.

+8
source

Make sure it is mod_rewriteturned on and you need a few lines in the .htaccess file, similarly:

RewriteEngine on
RewriteBase /
RewriteRule (.*)$ index.php?id=$1 [L]

( ) "htaccess pretty urls" .

+2

If you cannot use mod_rewrite (this is the best way), you can use the 404 trap.

That is, usually example.com/2222 will show 404 to the user. If you configured the server for the script of your choice instead of the default 404 page, now you can take the example.com/2222 URL and redirect the user to wherever you want.

+2
source

Source: https://habr.com/ru/post/1734953/


All Articles