301 redirects is not working with long query string - apache

I have a long url with query string which i want to redirect permanently to a new URL but its not working.
I am writing following to the .htaccess file
Redirect 301 /view-all/?c=low-loader-transport&c_new_value=false&sc=&sc_new_value=false&State_Suburb=on&lsu=&lsu_new_value=false&lst=&lst_new_value=false&l_ht[]=607&l_ht[_new_value]=false&l_t=578&search-now.x=80&search-now.y=21 http://www.testdomain.com/low-loader-transport
Am i doing something wrong?
There is one more 301 redirect in my htaccess file which is working fine. see following URL which works fine :
Redirect 301 /index.php http://www.testdomain.com
Any help would be appreciated.
Thanks.

You cannot match query string using Redirect directive. Use mod_rewrite rule like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^c=low-loader-transport&c_new_value=false&sc=&sc_new_value=false&State_Suburb=on&lsu=&lsu_new_value=false&lst=&lst_new_value=false&l_ht[]=607&l_ht[_new_value]=false&l_t=578&search-now.x=80&search-now\.y=21$
RewriteRule ^view-all/?$ http://www.testdomain.com/low-loader-transport/? [L,R=301]

Related

Redirect / Rewrite with .htaccess of an url containing :

I'm trying to redirect from /index.php?option=com_k2&view=itemlist&task=category&id=44:pinco to google.it
Note the special char :
But it doesn't seem to work.
This is one of the tests I've tried. Where am I wrong?
redirect 301 /?option=com_k2&view=item&id=44:pinco http://www.google.it
You can not redirect Query String using Redirect directive. You need to check Query String using ℅{QUERY_STRING} variable.
RewriteEngine on
RewriteCond ℅{QUERY_STRING} ^option=com_k2&view=itemlist&task=category&id=44:pinco$
RewriteRule ^index\.php$ http://google.it? [L,R]

htaccess 301 redirect with ? (question mark) in URL not working

This is probably a simple question, but I can not find why the 301 with an ? in the URL is not working. I have done a 301 redirect in the .htacces file but it´s not working. Other 301-redirects are working except for the one with a question mark in the URL.
I want http://www.example.com/?forum=2115543 redirected to http://www.example.com but the simple standard 301-redirect doesn´t work.
Example in .htaccess: Redirect 301 /?forum=2115543 /
You can not match a query string with Redirect (mod_alias). You need to use mod_rewrite.
You can give this a try.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^forum=(.+) [NC]
RewriteRule ^ /? [R=301,L]

Htaccess not working with?

I'm trying to redirect a list of URLs, but any of them that have a ? it isn't working. For example, here's my line of code...
Redirect 301 /calendar-of-events/day/date/2013-03-28/227.html?print=1&tmpl=component https://example.com/index.php/calendar/
This doesn't redirect. However, if I use this...
Redirect 301 /calendar-of-events/day/date/2013-03-28/227.html https://example.com/index.php/calendar/
...or this...
Redirect 301 /calendar-of-events/day/date/2013-03-28/227.html&tmpl=component https://example.com/index.php/calendar/
...and test the URLs out, they redirect correctly.
Any ideas on how to get this working?
You can't match query string using Redirect directive. Use mod_rewrite instead:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^print=1&tmpl=component$ [NC]
RewriteRule ^calendar-of-events/day/date/2013-03-28/227\.html$ https://example.com/index.php/calendar/? [L,R=301]

Simple 301 redirect in .htaccess with query string does not work with Redirect directive

I am trying to redirect a single URL in a .htaccess file with Redirect:
Redirect 301 /index2.php?option=com_rss&feed=RSS2.0&no_html=1 /something/somethingelse/
I have a bunch of other similar rules which work using directory structure URLs, but this one refuses to get processed.
Redirect 301 /old/url/ /new/url/
Do I have to do anything special?
Thanks!
With Redirect you can only test for URL paths, or more specifically, URL path prefixes but not for the URL query. But you can do so with mod_rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} =option=com_rss&feed=RSS2.0&no_html=1
RewriteRule ^index2\.php$ /something/somethingelse/? [L,R=301]

Properly 301 redirect an URL with parameters to a different site

Right now I have an outdated URL that is getting 404'd:
http://mysite.com/category/?tag=blue-example
It needs to be redirected to:
http://subdomain.mysite.com/blue/
This doesn't work:
Redirect 301 /category/?tag=blue-example http://subdomain.mysite.com/blue/
How do I properly rewrite this URL?
The mod_alias does only chech the URI path and not the query (the part after the ?). But you can use mod_rewrite for this:
RewriteEngine on
RewriteCond %{QUERY_STRING} =tag=blue-example
RewriteRule ^category/$ http://subdomain.example.com/blue/? [L,R=301]