Search code examples
apache.htaccessmod-rewriteurl-rewritingfriendly-url

how to get PHP Smart URL


My website has URL like this

domain.com/profile.php?id=your_profile_id

now how do i turn it into URL like this

domain.com/profile/your_profile_id

I tried this thing in .htaccess

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

and it's just helps me to remove .php extension. not the exact thing what i want. Thanks in advance. have a great day.


Solution

  • With your shown samples, please try following rules. Please make sure to place your htaccess file along with your profile.php file.

    Also please make sure to clear your browser cache before testing your URLs.

    RewriteEngine ON
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]*)/(.*)/?$ $1.php?id=$2 [QSA,L]