htaccess dynamically rewrite - .htaccess

example:
https://www.mydomain.de/myproduct/?___store=french&___from_store=german
to
https://www.mydomain.de/myproduct/
I have a store and want to dynamically permanent rewrite storeviews of hundrets of urls to one part of the same url.
And this for many URLs at ones redirecting via 301 to the product part
Can you help me?

You can use this rule to strip off the query string:
RewriteCond %{QUERY_STRING} ___store=
RewriteCond %{QUERY_STRING} ___from_store=
RewriteRule (.*) $1? [R=301,QSD,L]
It checks if the query string containing ___store= and ___from_store=, then redirect to the same URL permanently without the query string.

Related

Htaccess 301 redirect with query string params

This is so elementary that you have to ask why it is so complex to implement.
Simply need to redirect one url to another on the same domain, the url contains query string aparams though:
I tried:
RewriteRule ^article.php?section=exclusive&id=543 articles/view/4639 [R=301,L]
I get page cannot be found - the redirect is not happening. I have other re-directs in the same htaccess which work. The query string params are causing problems, and escaping them also does not help.
Note the id's of the two urls are not the same and therefore I don't want a clever re-write rule which converts from one url to another with the query strings mapped to new params. I just want a fast and dirty mapping from A to B.
UPDATE
I tried this it redirects but it is adding my old query string to the end of the new url. How can I prevent that?
RewriteCond %{REQUEST_URI} ^/article\.php$
RewriteCond %{QUERY_STRING} ^section=exclusive
RewriteRule ^$ http://www.onlinegooner.com/articles/view/3000 [R=301,L]
Input url is: mydomain.com/article.php?section=exclusive
You may use this rule:
RewriteCond %{QUERY_STRING} ^section=exclusive [NC]
RewriteRule ^article\.php$ /articles/view/3000? [R=301,L,NC]
? in the target will strip off previous query string.

htaccess redirect url by adding parameters

Need Guidance of 301 redirecting Url through htaccess matching specific format
Existing URL
http://www.example.com/index.php?option=com_toys&limitstart=20
Proposed URL
http://www.example.com/index.php?option=com_toys&view=list&Itemid=2&limitstart=20
Here limitstart may change to 0,20,40,60 to even 1000 and thus should remain same in the new proposed url too
Can anyone advise on to redirect using htaccess of above
You need to match query string using RewriteCond using a regex to capture both parameters:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(option=com_toys)&(limitstart=\d+)$ [NC]
RewriteRule ^/?index\.php$ %{REQUEST_URI}?%1&view=list&Itemid=2&%2 [L,NC,R=301]

Redirecting based on query string

Hi all I need to redirect based on query string though htaccess in Apache.
I want that all the queries that contain jjj redirect to my homepage
I used the code below but its not working could you please help me¿
Thanks in advance,
Mauri
RewriteCond %{QUERY_STRING} ^jjj$
RewriteRule (.*) http://www.eventosbarcelona.com [R=301,L]
Your rule redirects example.com/?jjj to example.com/?jjj I guess, You are getting redirect loop error as both urls are same. By default, mod-rewrite appends old query strings to the destination url. You need to use a ? at the end of the Rewrite destination url to discard query string.
Try this :
RewriteEngine on
RewriteCond %{QUERY_STRING} ^jjj$
RewriteRule (.*) http://example.com? [L,R]
This will redirect /?jjj to http://example.com/ .

Redirect query with specific word in the string

I am wanting to redirect any search query in the folder /catalogsearch/result/?q= that contains .com
This can be redirect to www.example.com/no-route
an example I would like to redirect would be www.example.com/catalogsearch/result/?q=spamwebsite.com
Make corresponding regex to QUERY_STRING.
RewriteCond %{QUERY_STRING} ^(.*)q=([^&]+)\.com(.*)$
RewriteRule ^catalogsearch/result/test /no-route [R=301]

Using .htaccess to redirect to a different URL based upon query strings

I am currently redirecting URLs with a query string that includes ‘Googleb0t’ to the same page without the query string, via the htaccess file, by adding the following:
RewriteCond %{QUERY_STRING} Googleb0t
RewriteRule ^(.*)$ $1? [L,NC,R=301]
So http://www.example.com/?Googleb0t would always redirect to http://www.example.com/
My question is how do you add multiple keywords to this directive in .htaccess if you have several parameters that need similar redirection?
If I also wanted URLs with different parameters, such as 'yah00' or 'bing' to 301 redirect the same way as URLs with 'Googleb0t' how would I do it?
Can this be accomplished in one single line of code?
RewriteCond %{QUERY_STRING} Googleb0t|yah00|bing

Resources