How do a I remove a specific query string in htaccess? - .htaccess

Hello and thanks in advance...
I have a situation where I need to completely remove the query string if it matches a pattern. I've been searching for an answer or even something close. So far, no luck. I've even tried a few things in my htaccess but without success.
The specific query string I need to remove is ?fbclid= and everything that comes after it.
Thank you!

Hard to say what your actual issue is, since you did not share your attempts so far. So we cannot help with those. All I can offer is another example. No idea if that helps.
This implements an internal rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^fbclid=
RewriteRule ^ %{REQUEST_URI} [QSD]
Here the variant for an external redirection:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^fbclid=
RewriteRule ^ %{REQUEST_URI} [QSD,R=301]
It always is a good idea to start out with a temporary 302 redirection and to only change that to a 301 once you are sure the current solution is final.

Related

Rewrite within a folder

This is very basic but still eludes me, even after studying the relevant stackoverflow pages.
I want this
mysite.net/special/
to return this (the index here)
mysite.net/info/special/
showing the requested address in the browser, not the longer actual address.
The closest I’ve got (with this in the root htaccess) is
RewriteRule ^special/$ info/special/ {QUERY_STRING}
but it’s wrong.
I had thought this is a direct match-and-replace, but apparently not.
RewriteEngine is on.
Guidance appreciated. Thank you.
RewriteRule ^special/$ info/special/ [R=301,QSA,L]
RewriteRule Flags:
R=301: redirect permanently
QSA: combine query string
L: last rule
I am assuming index as index.php for your index file. we are rewriting to your existing url.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/special/$
RewriteRule ^ info/special/index.php [L]

Opencart multistore "domain.com/aaa" instead of "aaa.domain.com"

Anyone can help to have "domain.com/store1/any-product" instead of "store1.domain.com/any-product"? The second is what I have and the first is what I would like to have.
Maybe some .htaccess code added? Anything else, please?
You should be able to achieve that by using the following rule in your .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^store1.example.com
RewriteRule ^(.*)$ http://example.com/store1/$1 [L,NC,QSA]
What the above does is if the condition for store1.example.com is met, then it will rewrite the URL to example.com/store1. This will also work for any other directories you have as a part of it. So it would become example.com/store1/about for example.
Make sure you clear your cache before you test this.

basic htaccess redirect by with variable move from URL (?id=1e34-2)

Ahoy all, I know these questions have been beaten to death. And even after my hour of research on stack, none of the suggestions or answers I have attempted have worked.
The only thing I am needing to do is....
Take the variable from a URL and redirect to another page (site), inserting that variable accordingly.
Keep in mind the variable can contain letters, dashes, underscores or numbers.
Original
/directory-here/a-random-name.php?strPropID=13d3-1
and I am redirecting to another domain.
http://www.someotherdomain.com/redirect.php?strPropID=13d3-1
So now I have this:
RewriteRule ^/directory-here/a-random-name.php\?strPropId=(.*)$ http://www.someotherdomain.com/redirect.php?propid=$1 [R=301,L]
However the redirect isn't working. What am I doing wrong here? I know it has to be something simple, no?
Thanks in advance!
You need to match query string using a RewriteCond not in RewriteRule:
RewriteEngine On
RewriteCond %{THE_REQUEST} /directory-here/a-random-name.php\?strPropId=([^\s&]*) [NC]
RewriteRule ^ http://www.someotherdomain.com/redirect.php?propid=%1 [R=301,L,NE]

htaccess RewriteRule not processing if not all parameters are passed

Hoping someone can help me with this issue...
I have a RewriteRule set up in my htaccess file that looks like this
RewriteRule ^/?find/(.+)/?in/(.+)/(.+)/ /page.html?&type=$1&city=$2&state_abbrev=$3 [L,QSA]
The rewrite works fine if I have a URL that contains all the parameters specified for example: http://www.site.com/find/doctors/in/dallas/tx/
The issue is, I would like to have this rewrite work even if one of the parameters is missing. For example, if I only entered http://www.site.com/find/doctors/ I would still want it to redirect to 'page.html' and just not have the parameters completed. So in that case it would be writing to http://www.site.com/page.html?type=doctors&city=&state_abbrev=. Currently, if I type in a URL that doesn't have all parameters in it the RewriteRule will not work. Any ideas how to fix this issue?
Thanks in advance...
Replace your rule with this:
RewriteRule ^/?find/([^/]+)(?:/in/?([^/]*)/?([^/]*)/?)? /page.html?type=$1&city=$2&state_abbrev=$3 [L,QSA]
There is nothing stopping you from having multiple rewrites. I have many in my .htaccess for different things and many times you have to. Not one rewrite will work for all occasions.
You could try this.
RewriteEngine on
RewriteRule ^find/(.*)/in/(.*)/(.*) page.html?type=$1&city=$2&state_abbrev=$3&%{QUERY_STRING} [L]
RewriteRule ^find/(.*) page.html?type=$1&%{QUERY_STRING} [L]
It will first look for the full URL
http://www.site.com/find/doctors/in/dallas/tx
Then forward it to the first Rewrite rule.
But then if you used this
http://www.site.com/find/doctors
It will skip the first rule and it will match the 2nd rule redirecting to just the partial query string.
Hope that helps but you can make as many rules or conditions you want. And the order in which they come does matter.

mod_rewrite remove query string on top of a rewrite rule

I have the following rewrite rule:
RewriteRule ^(.*)-task-(.*)\.html$ /index.php/task/name/$2\-task\-$1 [L]
When I tried to open:
/heru-task-number-1.html
It is working fine. HOwever, when there is a query string appended to it:
/heru-task-number-1.html?whatever=value
It is actually not calling the correct rewrite. Thus, I wonder how can I make sure so that both:
/heru-task-number-1.html
AND
/heru-task-number-1.html?whatever=value
are actually calling the same thing that is:
/index.php/task/name/$2\-task\-$1
I have tried to do this but to no avail.
RewriteRule ^(.*)-task-(.*)\.html\?(.*)$ /index.php/task/name/$2\-task\-$1 [L]
Thank you for your help or feedback on this.
This is fixed by inserting the following code at the top of htaccess:
RewriteCond %{QUERY_STRING} (^|&)fb_comment_id=
RewriteRule ^(.*)$ /$1? [L,R=301]
basically, what it does is that it will remove any extra query string that has fb_comment_id and redirect 301 to the one without query string.
Thank you #oddant and #Gerben for helping out!

Resources