How to create a clean url using apache and php?
I have build a basic blog application, where an admin can write the article in backend and the users can read it from frontend. i want to make my URL pretty so that it becomes SEO friendly. the url of the articles look like,
http://example.com/news.php?id=22
http://example.com/news.php?id=23
http://example.com/news.php?id=24
http://example.com/news.php?id=25
I want to make it clean and user or SEO friendly, what i want to achieve is in the news table in database i have a column name called title, and i want to display it as URI along with the combination of date. for example i want the URL to be like
http://example.com/news/010开发者_如何学C92010/this-is-first-news-title
how do i do it. is there any article that might be of help to me?
Thanks in advance
My recommendation is just to use mod-rewrite to direct everything to your index page using something like this...
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Then once everything is directed to your index create a front controller that looks at the request and loads the appropriate page.
It's much simpler/easier to maintain than trying to do everything with mod rewrite
Here is a beginners guide to mod-rewrite
http://www.workingwith.me.uk/articles/scripting/mod_rewrite
Take a look at ModRewrite
You can use maps to link id to text for instance
精彩评论