The basics of human-readable URLs

There is Apache, PHP and sabzh. I want to make human-readable urls (Friendly URL) on my site. Read about mod_rewriteand FilesMatch. Tell me what is better to choose? What to read on this topic? M.b. who has already done it, knows, throw a sample? I want to do it quickly, practically and safely.


Answer 1, authority 100%

I propose the following scheme:
Use mod_rewrite and write the following in htaccess (so that you don’t have to add it to each new window later):

RewriteEngine On
RewriteBase /
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/?_p=$0 [L]

You can remove the following lines:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

They are needed in order for the script in the attached files to be picked up (suppose you placed a forum in the /forum/ folder. Without these lines, it will not start (or rather, without the last one)).

How I do the processing in the script now (I take into account that the parameters are separated by a slash and the first parameter is the page to be displayed):

define('HTACCESS_GET_PATH_URL','_p');
define('DEFAULT_PAGE_CODE','main');
...
function _get(){
    if(isset($_GET[HTACCESS_GET_PATH_URL]))
        return explode('/',$_GET[HTACCESS_GET_PATH_URL]);
return array(DEFAULT_PAGE_CODE);
}
...
   :
$argv=_get();
$pageCode=basename(array_shift($argv));
      ( ),       .
      /view/123/
 ,    ,   0  123.    :
if(!$id=array_shift($this->argv)){
    ...   id    
}
... work...

I hope you find it useful. I started like you, I took a steam bath every time to write cnc for each page, then I got tired, and did it. The idea is not mine, but fine-tuned for myself!

As for FileMatch – if I’m not mistaken, then this does not apply to pu at all, but to the server’s file privacy settings, as an example (I hide the sources):

<FilesMatch "\.(inc)$">
  Order allow,deny
  Deny from all
</FilesMatch>

Where to write it?: at your discretion and depending on what is available to you: apache config, then you can write it there. Well, if you rent from a provider, then htaccess (it is intended for this).

It will work if mod_rewrite is enabled by the provider.