There is such a code

RewriteEngine on RewriteRule ^([-a-zA-Z0-9_]+)/([0-9]+)/? index.php?page=$1&id=$2 [L] 

When you enter http: // localhost / document / 1 / - everything works fine

what if

http: // localhost / document / - error

How to make the second variable optional?

  • Dmitry, tell me the manuals on your example! Where did you find this? - Roman St

1 answer 1

Try this:

 RewriteEngine on RewriteRule ^([-a-zA-Z0-9_]+)/?([0-9]+)?/? index.php?page=$1&id=$2 [L] 
  • Now if the link is localhost / document / 1 (without a slash at the end) then the id is not transmitted at all and all the pictures on the page have disappeared - Dmitry Nagulin
  • Are you sure that everyone copied? This is what var_dump gives me ($ _ GET); located at the very beginning of index.php, if I address to the address " localhost / document / 1 " - array(2) { ["page"]=> string(8) "document" ["id"]=> string(1) "1" } . PS and the same thing if I address the same address, but with a slash at the end. - GLAGOLA