This question has already been answered:

I need to make the link page1 from the link page.php? Id = 1 link to remove .php? Id = and can it be done with the help of .htaccess

Reported as a duplicate by Grundy , user194374, aleksandr barakin , Mr. Black , dirkgntly Aug 3 '16 at 8:42 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

2 answers 2

You need to do something like this here.

RewriteRule ^page([0-9]*)(/?)$ /page.php?id=$1 [L,QSA] 

That is, we convert the path /page123 to /page.php?id=123 using regular expressions in the .htaccess file

As for the link to this question , then everything is done simply - all query paths are passed as an _route variable in a GET request to the index.php file. This allows all the routing logic to be implemented in php - to parse the query string and include the necessary files via require or include . This approach is more rational in the sense that it is better to make a single routing system, rather than insert crutches every time, like what I suggested now.

  • You misunderstand me. I need the opposite from the page.php link? id = 123 to make the link page123 - BedOmar
  • @BedOmar I did just that - if you follow the link page123 then the effect will be as if you follow the link page.php?id=123 . The reference page123 means nothing by default, since it does not indicate a file (or a folder). In htaccess, we decipher this link and therefore it starts to work - RussCoder
  • I am writing a file not found - BedOmar
  • @BedOmar try to give more information about the problem. And I can not guarantee that everything is really right, perfect, here the idea is shown how to do it. You can also put the terms RewriteCond% {REQUEST_FILENAME}! -F RewriteCond% {REQUEST_FILENAME}! -D - RussCoder

Register in .htaccess

 RewriteEngine On RewriteRule ^page([a-zA-Z0-9_-]+)$ page.php?id=$1 RewriteRule ^page([a-zA-Z0-9_-]+)/$ page.php?id=$1 
  • Please try to write more detailed answers. I am sure the author of the question would be grateful for your expert commentary on the code above. - Nicolas Chabanovsky
  • @NicolasChabanovsky + - BedOmar