views:

270

answers:

4

I have been taken in to provide some SEO guidance on a website which has been running since 2005. My problem is I want to use clean URLs.

The code that handles the URL is hidden away in some class file. And with over a few thousand lines of code its a struggle to rewrite it.

So I'm think, I have gone through all the products and created a slug for them as a field in the product table. Is it possible to do something like an intermediate file for .htaccess?

Some thing like

  1. /clean-slug-comes-in/
  2. .htaccess catches this and uses slug.php to find the relevant product ID for the slug.
  3. Then product.php?id=(ID.found.from.2) is loaded.
A: 

You can chain rewrite rules, but AFAIK there's no way to execute two scripts in the same request and use the output from 1 as a parameter in the second.

Felix
+2  A: 

slug.php:

$id="ID.found.from.2";
include 'product.php';
Col. Shrapnel
the way it works is that one file does everything. so display categories, shopping cart, and displaying products. Which is killing its seo potential
chris
@chris that is exactly what you're asking for. and it has nothing to do with SEO. They call it "router"
Col. Shrapnel
This is a good solution, but you will probably have to review `product.php` because it's now getting `$id` directly and not via `$_GET`
kemp
CAn you not change a $_GET variable? aka $_GET['var'] = 5?
chris
@Chris it is possible but considered very dirty trick :)
Col. Shrapnel
Alright. sure the code will be abstracted away from possible user tampering
chris
A: 

You could use a PHP script as rewrite map (see RewriteMap directive). But that’s quite difficult.

It would be easier if you send the slug to your slug.php script, fetch the ID from the database, set $_GET['id'] with that value, and then include the product.php script.

Gumbo
A: 

Another solution came to my mind:

Eeverything remains the same, but slug.php being included into every module, doing job of converting slugs into ids

Even better if you already have some config file being included into every module.

Col. Shrapnel