0

I've been looking around for a method to simplify URL query strings, ultimately to create more SEO friendly URLs.

Essentially, where a standard URL using $_GET in PHP might be: website.com/portfolio/item.php?id=item-slug...

I'd like it to be: website.com/portfolio/item-slug.

I'm aware there are many ways of achieving this, some involving .htaccess, but I haven't been able to find one prefered method. Can anyone tell me what the most convenient, up to date method might be?

Splycd
  • 161
  • 2
  • 3
  • 15

1 Answers1

2

The fastest, most organized, accepted, and up-to-date way is through Apache's mod_rewrite.

# Enable rewriting
RewriteEngine On

# Set the base (where the rewrite engine will listen for)
RewriteBase /

# Interpret "portfolio/(ARG)" as "portfolio/item.php?id=(ARG)"
RewriteRule ^portfolio/(*.)$ portfolio/item.php?id=$1 [L]

Even though it is very convenient and easy to put it inside the .htaccess. It actually preforms faster if you put it in your sites configuration. But it's whatever you prefer really.

Dellowar
  • 3,160
  • 1
  • 18
  • 37
  • Awesome! I think I need to have a more in depth look into what can be done with .htaccess, I'm fairly new to playing with it. – Splycd Nov 15 '16 at 16:51