Question

Remove parameter in URL with .htaccess

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.


Submit an answer


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!

Sign In or Sign Up to Answer

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.

KFSys
Site Moderator
Site Moderator badge
January 7, 2022
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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

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.