Create page without posting .php at the end?

I was looking for ways to imitate something that I saw, but I'm not even sure where to start or how to look for it.

Say my page was:

foo.com/, and my index page can take an argument: index.php? id = 5

I want to do the following:

foo.com/5/ instead of index.php? id = 5 just use the web string to pass in the parameters to hide not only the fact of its PHP page, but also clear the URL a bit more.

Is it possible?

Greetings

+3
source share
4 answers

You will want to learn about URL rewriting. With the widely used Apache web server, this is accomplished with mod_rewrite.

+11
source

/? 5/123/ php ,

+2

- :

RewriteRule ^pages/([A-Za-z_-]*)(/?)$ /index.php?page=$1

Failure, we are looking for a URL that starts with pages, has any combination of letters, underscores, and hyphens, as well as an optional forward slash and pass it to /index.php for processing.

+2
source

Yes Mod_rewrite is the best option, you can create a .htaccess file. unless you want to write a custom function that will process your URL.

0
source

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


All Articles