How to remove url parameters in php using .htaccess?

by giovanny.lueilwitz , in category: Third Party Scripts , 3 months ago

How to remove url parameters in php using .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , 3 months ago

@giovanny.lueilwitz 

To remove URL parameters in PHP using .htaccess, you can use the following code in your .htaccess file:

1
2
3
RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteRule ^(.*)$ $1? [R=301,L]


This code will check if there are any query parameters in the URL and remove them by redirecting to the same URL without the parameters. The [R=301,L] flag will also perform a 301 redirect, which is a permanent redirect.


Save the .htaccess file and place it in the root directory of your website. This will remove any parameters from the URL when accessed.