Page 1 of 1
how to create custom file name
Posted: Fri Jun 05, 2009 4:44 pm
by anand
I am sure this website uses PHP/MySQL, so my question is, how can it create a custom url like this : -
http://www.mouthshut.com/product-reviews/Kentucky_Fried_Chicken_-Fast_Food_Chain-925009819.html
http://www.mouthshut.com/product-review ... 09819.html
I might sound lame but I really need your advice as I can't figure it out.

Re: how to create custom file name
Posted: Fri Jun 05, 2009 4:55 pm
by Darhazer
The quick answer is mod_rewrite and .htaccess

Re: how to create custom file name
Posted: Fri Jun 05, 2009 5:13 pm
by anand
Darhazer wrote:The quick answer is mod_rewrite and .htaccess

i was thinking the same. but how can it be so specific?
like,
http://www.example.com/kfc-chicken.html
http://www.example.com/apple-macbook-air.html
and, lets say, i start a topic on "2008 beijing world cup" then it'll pull up a page like
http://www.example.com/2008-beijing-world-cup.html
Re: how to create custom file name
Posted: Fri Jun 05, 2009 5:48 pm
by requinix
You saw that number at the end of the URL?
http://www.mouthshut.com/product-reviews/What-shows-up-in-here-doesnt-actually-matter-925009819.html -
try it
That's how the system knows which article/page you requested. It finds the number at the end, looks up the page according to that number, and displays it. Adding the title in there is just to make it friendlier to people (which has a nice side effect of making it rank better in search engines).
You can do it by title if you want, but it's more of a hassle because you have to check uppercase versus lowercase, converting "invalid" characters to hyphens, and so on.
But the process is the same: you grab the title from the URL, look it up in your database, and figure out which page to display.
Re: how to create custom file name
Posted: Fri Jun 05, 2009 7:46 pm
by mikemike
As a starting hint, the following in your .htaccess will forward everything to index.php
Code: Select all
RewriteEngine on
RewriteCond $1 !^(index\.php|default\.css|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
index.php, default.css, your images folder and robots.txt are ignored.
Re: how to create custom file name
Posted: Sat Jun 06, 2009 11:51 pm
by anand
Thanks guys.
Espicially, tasairis
Re: how to create custom file name
Posted: Sun Jun 07, 2009 11:03 am
by mikemike
Charming
