0

I want to change the url from

  http://localhost/brand/2-BBB.html

to

 http://localhost/brand/BBB-2.html

appreciate if you can help me

RewriteEngine On
RewriteBase /
RewriteRule ^brand/([0-9]+)-(.*)\.html$ test.php?id=$1
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • Have you tried to google it? https://help.dreamhost.com/hc/en-us/articles/215747748-How-can-I-redirect-and-rewrite-my-URLs-with-an-htaccess-file- – Mech Mar 25 '20 at 16:35
  • 1
    Does this answer your question? [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – MrWhite Mar 25 '20 at 16:42
  • @Mech I tried but no results if I use htaccess above, it works but when I change the ID behind it can't work (.*)-[0-9]+)] – Ary Syahputra Mar 25 '20 at 16:42
  • https://stackoverflow.com/questions/60851087/how-to-make-a-url-seo-friendly – CBroe Mar 26 '20 at 07:34

1 Answers1

0

Assuming you've changed the URLs in your application to the new /BBB-2.html version, then you just need to change your directive like this:

RewriteRule ^brand/(.+)-([0-9]+)\.html$ test.php?id=$2 [L]

Note the $2 backreference.

MrWhite
  • 43,179
  • 8
  • 60
  • 84