php - Username not displaying in URL even when specifying Rewrite rules -


i struggling understanding how modify url using rewrite rules. have seen following link : directly adding username url php - following knowledge not seem work me.

i need url eg. http://localhost/profile_page/freddy

rather than: http://localhost/profile_page.php

.htaccess (which located in in default wamp folder, c:\wamp\www)

    rewriteengine on     rewritebase /wamp/www/      rewriterule ^/?$ profile_page.php     rewriterule ^/me?$ profile_page.php     rewriterule ^/profile_page.php/([a-za-z0-9_\-]+)/?$ profile_page.php?u=$1     rewriterule ^/profile/([a-za-z0-9_\-]+)/?$ profile_page.php?u=$1     rewriterule ^/([a-za-z0-9_\-]+)/?$ profile_page.php?u=$1 

i have following questions:

1. rules above, although have limited knowledge in field, expect convert url of http://localhost/profile_page.php display name of user logged in i.e. http://localhost/profile_page/freddy.

details of user logged in can gained session variable $username or variable $user obtains username of user after "u=" in url (see below). however, url not display name of user logged in, says http://localhost/profile_page.php when, if logged in freddy, want http://localhost/profile_page/freddy.

<?php     $user = "";     if (isset($_get['u'])) {         $user = ($_get['u']);         if (ctype_alnum($user)) { //check if user exists             $check = mysqli_query($connect, "select * users username='$user'");             if (mysqli_num_rows($check) === 1) {                 $get        = mysqli_fetch_assoc($check);                 $user       = $get['username'];                 $fname      = $get['first_name'];                 echo "<h2>profile page for: $user</h2>";             } else { // refresh page                  echo "<meta http-equiv=\"refresh\" content=\"0; url=http://localhost/index.php\">";                 exit();             }         }     } ?> 

2. if, in url, type http://localhost/profile_page.php?u=fred, echo's on fred's page, displays profile page of user logged in, displays posts , information freddy, rather fred, specified in url.

you can replace .htaccess this:

options -multiviews rewriteengine on rewritebase /  rewriterule ^(me)?/?$ profile_page.php [l,nc]  rewriterule ^profile(?:_page)?/([\w-]+)/?$ profile_page.php?u=$1 [l,qsa,nc]  rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^([\w-]+)/?$ profile_page.php?u=$1 [l,qsa] 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -