How to create dynamic/friendly URLs using PHP?
Can anyone explain how to create fr开发者_JAVA百科iendly URLs? I mean URLs like http://store.steampowered.com/app/22600/
that doesn't have any pages like index.php
visible.
If you only have cpanel use .htaccess.
If that doesn't work, you are left with parsing the url in php with a link like this:
http://server.com/router.php/search
You can do that with something like this.
<?
list($junk,$url) = explode("router.php",$_SERVER['REQUEST_URI']);
$paths = explode("/", $url);
if ($paths[0] == 'search')
{
Header("Location: /search.php");
}
?>
http://articles.sitepoint.com/article/search-engine-friendly-urls
http://www.alistapart.com/articles/succeed/
Search revealed dozens more
You need to look up apache mod_rewrite (assuming you are using apache for your web server). PHP itself doesn't do it for you the web server does most of the work. You need to tell your web server to use mod_rewrite to point all urls that match a certain pattern to point to what ever .php file you like. You can pass arguments in your url pattern what ever way you choose. e.g. using the / to delimit key values or just values. If you don't have root access to the server and its enabled you can usually put these mod rewrite rules in a .htaccess file at the root of your site.
Sitepoint have a good reference for beginners. http://articles.sitepoint.com/article/guide-url-rewriting
if you're using apache this should work/is the idea:
RewriteRule ^(.*)$ /index.php?/$1 [L]
now your url will go to http://store.steampowered.com/index.php/app/22600/
精彩评论