How to use $_GET parameter to make seo friendly urls?

后端 未结 2 1903
忘了有多久
忘了有多久 2021-01-03 13:02

I am using a PHP CMS that I\'ve made myself. It fetches the $_GET parameter url and turns it into www.website.com/{url}. This CMS uses the $_GET pa

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-03 13:21

    You can have the second parameter ( {username} ) be a local variable before you include the file, in which you can then access it as an ordinary variable. This is not a good thing to do if you're working with a team.

    EDIT:

    What you can do is the following

    RewriteEngine On  
    RewriteRule ^ index.php
    

    Then in index.php you can have this

    $url = str_replace('index.php','', $_SERVER['PHP_SELF']);
    $url = str_replace($url,'',$_SERVER['REQUEST_URI']);
    $url = explode('/',$url);
    $page = array_shift($url);
    foreach ($url as $val){
        $args[] = urldecode($val);
    }
    

    Now if you open the link www.website.com/profile/someuser/about you will have

    $page = 'profile'
    $args[0] = 'someuser'
    $args[1] = 'about'
    

    And so on you can have as much arguments as you like.

提交回复
热议问题