0

I'm programmer, I need a best practice to create a SEO friendly blog post URLs on PHP with specific pattern and logic.

Let say I have a table containing user_id, post_name, post_content, post_category, and post_date with this illustration table:

+----------+-----------+-----------------+---------------+---------------------+
| user_id  | post_name | post_content    | post_category | post_date           |
+----------+-----------+-----------------+---------------+---------------------+
| johnblog | my book   | lorem ipsum     | book          | 2014-09-02 11:44:25 |
| doeblog  | a coder   | dolor sit amet  | code          | 2014-08-29 11:17:16 |
| johnblog | something | consectetuer    | other         | 2014-07-25 12:18:46 |
| aldofoe  | true story| adipiscing elit | story         | 2014-07-20 12:23:20 |
+----------+-----------+-----------------+---------------+---------------------+

From this table, I want to make a structured user friendly URLs based on post_date, for example:

http://{user_id}.domain.com/{year}/{month}/{day}/{post_name}.html
eg: http://johnblog.domain.com/2014/09/02/lorem-ipsum.html

Logic rules:
1. If user go to http://johnblog.domain.com/2014/ show only johnblog's posts in that year.
2. if user go to http://johnblog.domain.com/2014/09/02/ show only johnblog's posts with specific post_date and so on.

What I need is a the best practice (like mapping user_id to the domain and sql queries) to play with this rules and I'll take the rest.

Thank you.

JrrMaster
  • 65
  • 1
  • 7
  • 2
    possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – Daan Sep 02 '14 at 08:35
  • This is not just a .htaccess rewrite rule and condition, I have a specific question like URLs correlation with database table and mapping to the subdomain. – JrrMaster Sep 02 '14 at 08:44
  • To begin with, you must ask your host to setup wildcard sub domain. It is possible to use `mod_rewrite` to match part of hostnames. – Salman A Sep 02 '14 at 08:45
  • Yes, I did, but I need a clue to make a wildcard subdomain mapped to its own user_id. – JrrMaster Sep 02 '14 at 08:48

0 Answers0