RewriteEngine on RewriteRule ^/post/([0-9])/$ index.php?post=$1 [L] Options -Indexes 

Here is my rule, I try to go to the site localhost / post / 1/404 says, maybe in the rule I wrote something wrong please help plz = 3

  • one
  • I know how it works. - cr1gger
  • try RewriteRule ^ post / ([0-9]) / $ index.php? post = $ 1 [L] - Alex
  • It's good that you know :) Just a very useful link and at the very beginning of the article the answer to your question. - ReinRaus

1 answer 1

The first RewriteRule is passed the path from the place where the .htaccess is located to the requested file. This line never starts with "/".

Thus, in RewriteRule you will have post/1/ (without a slash in the beginning), which does not coincide with your regularization.

To make it work, you need:

  1. Specify the regular season without a slash at the beginning.
  2. Write RewriteBase / to avoid redirect artifacts.

Total should be:

 RewriteEngine on RewriteBase / RewriteRule ^post/([0-9])/$ index.php?post=$1 [L] 
  • Instead of [0-9] you can use \d . And in order to be able to specify not only a number from 0 to 9 , but generally any, you can use \d+ . - user194374