-5

I am building a PHP based application which has users. Currently I have a view profile directory which has an index.php.

When a user clicks on another user's picture, I redirect them to view-profile/?u="username"

Due to this I do a get of u and show profile accordingly.

Is there a way to change the URL path to something like root/view-profile/username or better can i make it something like root/username

Is this possible through htaccess? If so, can someone please help me with this.

Gaurav Mehta
  • 1,073
  • 4
  • 15
  • 27

1 Answers1

0

Is there a way to change the URL path to something like root/view-profile/username or better can i make it something like root/username

No better keep it like /profile/username instead of /username otherwise every not found page will be treated like user profile page.

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteRule ^profile/([^/]+)/?$ /view-profile/?u=$1 [L,NC,QSA]

Reference: Apache mod_rewrite Introduction

anubhava
  • 713,503
  • 59
  • 514
  • 593