htaccess redirect url by adding parameters - .htaccess

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]

Related

htaccess dynamically rewrite

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.

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 only one URL with parameter

I need to redirect URL, for example:
www.mydomain.com/category/sub-category/product?page=shop.ask&flypage=flypage.tpl&product_id=181&category_id=34
To:
www.mydomain.com/category/sub-category/good-product.html
I have a multiple URLs with parameters that need to be redirected to only one or couple of URLs, can you help me, I used Google for hours.
I was try this code at .htaccess:
redirect 301 /category/sub-category/product?page=shop.ask&flypage=flypage.tpl&product_id=181&category_id=34 www.mydomain.com/category/sub-category/good-product.html
But it doesn't work.
You can't match against the query string in a Redirect directive. You'll need to use mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page=shop.ask&flypage=flypage.tpl&product_id=181&category_id=34$
RewriteRule ^category/sub-category/product$ /category/sub-category/good-product.html? [L,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

301 Redirects problem - urls with ? and =

I'm new with 301 redirects through .htacces.
I can get simple redirects as
redirect 301 /test.html http://www.domain.com/test2.html
to work but I have some urls like this
redirect 301 /test.asp?Group=100 http://www.domain.com/test3.html
and for some reason these don't work.
Thanks.
Here is set of rules for URLs you have provided:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} =group=113 [NC]
RewriteRule ^group\.asp$ http://domain.dk/til-born.htm? [NC,R=301,L]
RewriteCond %{QUERY_STRING} =product=1136 [NC]
RewriteRule ^product\.asp$ http://www.domain.dk/til-born/bukser.html? [NC,R=301,L]
As you can see query string is matched separately to the page name. So .. for each of such redirects you need 2 lines: RewriteCond & RewriteRule.
The rule above will do EXACT match, which means /group.asp?group=113&param=value will not be redirected because query string is group=113&param=value which is more than just group=113.
To have such redirect working (when there are some optional parameters in query string) you have to modify it: RewriteCond %{QUERY_STRING} (^|&)group=113(&|$) [NC] -- this will match group=133 anywhere in query string (group=113 and group=11366 are still different, so no problems here).
This needs to be placed in .htaccess in website root folder. If placed elsewhere some tweaking may be required.
The Redirect directive (as far as I know) matches only on the path, not querystring. Instead, use RewriteRule. The QSA instructs the rewrite engine to append the querystring onto the new redirected URL.
RewriteEngine On
RewriteRule ^test\.asp http://www.domain.com/test3.html [L,R=301,QSA]

Resources