开发者

How to create dynamic/friendly URLs using PHP?

开发者 https://www.devze.com 2023-01-10 01:39 出处:网络
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

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号