简体   繁体   中英

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/01092010/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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM