Reputation: 115
I have database table in this structure:
id title description URL
1 abc abc desc abc
2 xyz xyz desc xyz-123
3 tit Description web-description
...
I need to generate web pages from my database table such as:
domain.com/abc
domain.com/xyz-123
domain.com/web-description
I dont´t know where and how to set rewrite rule to take it from my database table. I don´t want to use robust framework such as Zend, I want only sample code to solve this problem. Please, any ideas? Thanks!
Upvotes: 1
Views: 706
Reputation: 525
You can do this from php and .htaccess file.
Your php file name should be index.php
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?id=$1
Thats all.
When you execute url another url has executed.
Ex:
domain.com/xyz-123
will execute domain.com/index.php?id=xyz-131
domain.com/web-description
will execute domain.com/index.php?id=web-description
Note: Apache rewite module should be enabled
Upvotes: 2
Reputation: 4511
You can read this tutorial, but you should really edit your question title to remove irrelevant "database" part from it.
Upvotes: 0