.htaccess, cnc, get parameter

Question:

What needs to be registered in htaccess to turn the link

http://domain/profile?id=1

v

http://domain/profile/id/1

Answer:

Use this code:

RewriteRule ^profile\?id=([0-9]+)$ profile/id/$1 [L]

The regex uses a capturing group that contains all the digits, and then substitutes them in the target URL using the $1 construct.

Also, do not forget to add at the beginning of the .htaccess file:

RewriteEngine On

and check that mod_rewrite is in your apache version.

Scroll to Top