0

As part of a project, we're currently looking at adding in SEO URLs to pages. This is for an online store, and there are numerous types of content within the site: static pages (for example "About Us", "Privacy Policy", product categories and product pages.

We have the numerous URL stubs stored in a MySQL table as follows:

+-----------------+------------------+----------------+
|    url_stub     | destination type | destination_id |
+-----------------+------------------+----------------+
| privacy-policy/ |       page       |       1        |
+-----------------+------------------+----------------+
|   category-1/   |     category     |       2        |
+-----------------+------------------+----------------+
|  my-product-1/  |      product     |       1        |
+-----------------+------------------+----------------+

One option to serve these up would be to have a huge index.php file which is capable of handling everything, however, we would much prefer to have separate pages to serve up the different content types. For example anything with a destination_type of page would go to page.php?id=#, and so forth. So, for the examples in the table above, these would be directed as follows:

privacy-policy/ = page.php?id=1
category-1/     = category.php?cat=2
my-product-1/   = product.php?prod=1

My question is this: what would be the best practice to achieve this? We don't want to include the destination_id anywhere in the SEO-friendly URL. I was thinking that it might be possible to create a dynamic .htaccess file which outputs everything on the fly with mod_rewrite, but I can't find any solutions.

Any help or comments would be most gratefully received.

1 Answer 1

1

Short answer would be "no you have to rewrite it every time" but this older question should answer yours :) Can I make a dynamic .htaccess file?

Otherwise, complicated/stupid/useless idea:

RewriteRule /(.*)  /index.php?url=$1

Then in your PHP file

if (isset($_GET['url']))
{
  //Parse url and echo page according to requested url
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Josh. So, are there any solutions at all?
Edited to give you the most dynamic rewrite you can have if you want to use a database for your rewrites.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.