0

I am trying to implement SEO friendly URLs using .htaccess and PHP.

My URL is:

http://www.my_web_site.com/instructions.php?topic_id=6&category=NNNX&t=a-b-c

I want to this:

http://www.my_web_site/6/a-b-c

Can someone please help me make a following .htaccess content

Thanks.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
bin2003
  • 25
  • 5
  • Rewrite rules. That's what you're looking for. (Despite what seemingly every question on this on Stack Overflow says, `.htaccess` has absolutely nothing to do with it. It's just a file name convention for putting your Apache config directives. Sure, you can put your rewrite rules there if you want, but even the Apache docs advise against this as that config has to be parsed and loaded for each applicable request.) – Brad Dec 05 '21 at 05:00

1 Answers1

0

You can use the following rule in your htaccess file to shorten your URLs

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.+)$ /instructions.php?topic_id=$1&category=NNNX&t=$2 [L]

With this rule , you can just type example.com/6/foobar instead of the full old URL path.

Amit Verma
  • 40,709
  • 21
  • 93
  • 115