Splycd Splycd - 11 months ago 53
HTML Question

Simplifying PHP URL query strings

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:

I'd like it to be:

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?

Answer Source

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.