skip to Main Content

I am using xamp to host my webpage on my PC and I want to change this url from

http://localhost/loginsystem/profile.php?user=myUsername

to

http://localhost/loginsystem/profile/myUsername 

I have tried the following and doesn’t work and in return gives server error 500.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^/profile/([a-zA-Z0-9]+) /profile.php?user=$1 [NC, L]

and

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^/profile/(.*)?$ /profile.php?user=$1 [NC, L]

Any help would be great still pretty new. Thanks in advance!

2

Answers


  1. This should do the trick

    RewriteRule ^profile/([^/]+)/?$ profile.php?user=$1 [L]
    

    Also make sure that your .htaccess file is in the loginsystem folder. Otherwise you will need to put this in your rewrite rule

    RewriteRule ^loginsystem/profile/([^/]+)/?$ profile.php?user=$1 [L]
    
    Login or Signup to reply.
  2. Replace .htaccess code with:

    Options +FollowSymLinks
    # Turn mod_rewrite on
    RewriteEngine On
    
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    
    RewriteRule ^profile/([a-zA-Z0-9]+)/$ profile.php?user=$1 [L]
    

    Now you can get user query with GET request.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search