Search code examples
phpurlseosearch-enginefriendly-url

How to rewrite url domain.com/?id=123456 => domain.com/123456/


How do I make a site with Search Engine friendly urls? Do I need special PHP code instead of:

$_GET['id']

How to access 'id' variable after rewriting URL?


Solution

  • Just add this to your htaccess file

    Options +FollowSymLinks
    RewriteEngine on
    
    RewriteRule /(.*) ?id=$1 [QSA,NC,L]
    

    note: if you already have

    Options +FollowSymLinks
    RewriteEngine On
    

    on your htaccess file, just place

    RewriteRule /(.*) ?id=$1 [QSA,NC,L]
    

    under it and ignore the rest

    instead of visiting domain.com/?id=123456, you now visit domain.com/123456/. then on that page you can still use $_GET['id'] the way you normally would