4

i'v been stuck with this <a href="profile.php?u=<?php echo $uiname ?>"/> , i'm trying to hide the $_GET variable but no success. what i'm trying to achieve is something like www.mywebsitename.com/profile/name or www.mywebsite.com/name instead of

profile.php?u=name

is it possible to do so ?

user2660611
  • 65
  • 1
  • 6
  • You can find your answer here. http://stackoverflow.com/questions/4448304/use-sos-url-format-for-get/4448518 – Jahanzeb Aug 17 '13 at 07:50

1 Answers1

3

For Your URL: http://localhost/ifinal/profile/myname

You can use like with htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ifinal/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^profile/(.*) profile.php?u=$1
</IfModule>

If your site not underfolder, use just RewriteBase /

And use HTML

<a href="profile/<?php echo $uiname; ?>">
   <?php echo $uiname; ?>
</a>
Bora
  • 10,529
  • 5
  • 43
  • 73
  • do i just create .htaccess and paste this to it ? RewriteRule ^profile/(.*) /profile.php?u=$1 or i need to add something else to the .htaccess ? – user2660611 Aug 17 '13 at 07:58
  • 1
    @user2660611 updated codes. copy and paste exactly to root `.htaccess` and let me know about you getting any error or not. hope it work – Bora Aug 17 '13 at 08:01
  • it doesnt work , i'm using wamp server. i enabled the apache rewrite module and i uncommented LoadModule rewrite_module modules/mod_rewrite.so from the httpd.conf and nothing changes – user2660611 Aug 17 '13 at 08:06
  • 1
    What you get? What exactly your url? Root or subfolder? – Bora Aug 17 '13 at 08:08
  • i get the same as the old ones. i'v two profile.php, one is at the main folder which includes some php files, and the actual profile.php is in subfolder called inc – user2660611 Aug 17 '13 at 08:09
  • 1
    Your site under subfolder? and if you enter `www.mywebsitename.com/profile/name` what you see? – Bora Aug 17 '13 at 08:11
  • ( ! ) Notice: Undefined index: u in C:\wamp\www\ifinal\func\user_profile_details.php on line 4 which i get the $_GET['u']; – user2660611 Aug 17 '13 at 08:17
  • 1
    It works for me. Updated codes. Try again pls. Watch out `RewriteBase` – Bora Aug 17 '13 at 08:24
  • nope it did not work , just to try whether the .htaccess working or nope, i deleted profile.php?u=$1 and its given me 500 internal error. which mean it works. but the url still the same http://localhost/ifinal/profile.php?u=myname – user2660611 Aug 17 '13 at 08:43
  • 1
    @user2660611 You made something wrong. It works for me. You have to define `RewriteBase /ifinal/` and enter `http://localhost/ifinal/profile/myname`. Updated codes – Bora Aug 17 '13 at 08:45
  • it works with http://localhost/ifinal/profile/myname but the layout doesn't show as u go to profile.php?u=myname and also it only works when you copy this to the address bar. http://localhost/ifinal/profile/myname but when you click on the href it open it as http://localhost/ifinal/profile.php?u=myname – user2660611 Aug 17 '13 at 08:53
  • 1
    Why you dont change your `href` links as `profile/myname` instead of `profile.php?u=myname`? – Bora Aug 17 '13 at 08:55
  • yeah it does work after i change that , but now my html layout has gone ! any idea why would that happen ? – user2660611 Aug 17 '13 at 09:02
  • 1
    @user2660611 Because of using `profile/myname` like under `profile` folder. Try updated codes. Or use `base href` tag : http://www.w3schools.com/tags/tag_base.asp – Bora Aug 17 '13 at 09:07
  • now it has become like this http://i.imgur.com/HDDblHY.png . i don't know why. maybe because i'm including the layout of the profile in the main profile in the main folder? – user2660611 Aug 17 '13 at 09:24
  • man that did it. i really appreciate your help. i really dooo. many thanks. – user2660611 Aug 17 '13 at 09:32