User friendly URLs - mod rewrite and php redirections

前端 未结 4 612
我在风中等你
我在风中等你 2021-01-18 13:18

So far I\'ve done this:

RewriteBase /
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule  ^(.*)$ index.php?load=$1 [QSA,L]         


        
4条回答
  •  情歌与酒
    2021-01-18 14:17

    A simple solution would be: EDIT HTACCESS

    RewriteBase /
    RewriteCond %{REQUEST_URI}  !/signup
    RewriteCond %{REQUEST_URI}  !/signin
    RewriteRule ^([^/]*)/([^/]*)$ index.php?load=gallery&username=$1&gallery=$2
    RewriteCond  %{REQUEST_FILENAME} !-f
    RewriteCond  %{REQUEST_FILENAME} !-d
    RewriteRule  ^(.*)$ index.php?load=$1 [QSA,L]
    

    Now that PHP part ( for index.php ):

    $load = $_GET['load'];
    switch ($load){
        default:
            include('home.php');
            exit();
        break;
        case 'dashboard':
            include('dashboard.php');
            exit();
        break;
        case 'about':
            include('about.php');
            exit();
        break;
        case 'gallery':
            $username = $_GET['username'];
            $gallery = $_GET['gallery'];
    
            //check for the username and gallery
    
            header("Location: your-gallery-location-goes-here");
        break;
    }
    

    Hopefully it's gonna help :)

提交回复
热议问题