Remove .php and id from url and replace with slash

南楼画角 提交于 2019-12-05 16:12:38
anubhava

Have your complete .htaccess like this:

  Options +FollowSymLinks -MultiViews
  # Turn mod_rewrite on
  RewriteEngine On
  RewriteBase /

  ## don't touch /forum URIs
  RewriteRule ^forums/ - [L,NC]

  RewriteCond %{THE_REQUEST} \s/+products(?:\.php)?\?id=([0-9]+) [NC]
  RewriteRule ^ products/%1? [R,L]

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

  ## hide .php extension snippet
  # To externally redirect /dir/foo.php to /dir/foo
  RewriteCond %{THE_REQUEST} \s([^.]+)\.php [NC]
  RewriteRule ^ %1 [R,L]

  # To internally forward /dir/foo to /dir/foo.php
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule ^(.+?)/?$ $1.php [L]

you need to use it like that

RewriteRule ^products/([0-9]+)$ products.php?id=$1

use below htaccess rule

RewriteRule ^products/([0-9]*)$ /product.php?id=$1 [L,QSA]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!