Report this

What is the reason for this report?

Remove parameter in URL with .htaccess

Posted on January 7, 2022

Hello Community,

I’m again trying to do some stuff with .htaccess and for some reason am not able to.

I want to remove a parameter from my URL. Let me give you an example, let’s say I have something in the lines of MyDomain.com/index.php?band=brend, I want to make it look like this MyDomain.com/brend.

I’ve tried a couple of options and so far managed to remove the extention from the link but to that extend.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
0

Accepted Answer

Hi @brendRos,

Nice seeing you again!

So, I think a redirect like the following should work:

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/index\.php\?band=(\S+)\s [NC]
RewriteRule ^ /%1? [R=301,L]

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

Also, just a quick note, you’ll need to pass your argument to index.php in the backend to make use of them but I’m sure you already know that.

.htaccess how to REMOVE PARAMETERS EXCLUDE SOME PAGES?

I used the following commands in .htaccess to remove the parameters of a URL SUCCESSFUL RewriteEngine on RewriteCond %{QUERY_STRING} !=“” RewriteRule ^(.*)$ /$1? [R=301,L]

For example: https://your-domain.com/product/apple1/?v=e14da64a5617 It will be successful https://your-domain.com/product/apple1/

However, it’s applied to all pages. If I just want to EXCLUDE for the following 2 pages, so how should I edit the .htaccess commands?

Url1: https://your-domain.com/cart/ Url2: https://your-domain.com/checkout/

Hope you can support me, thanks. Nguyen

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.