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

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]

Related

301 redirects is not working with long query string

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]

Website article .htaccess 301 redirect

I have a site in a folder called patients and my urls look like so:
http://site.com/patients/post-name
http://site.com/patients/articles/another-post-name
I want to redirect them all to a clean:
http://newsite.com/post-name
http://newsite.com/another-post-name
In other words, lose the /articles/ which sometimes appears and 301 to the new site.
Any help on how to do this with htaccess?
Edit your .htaccess in http://site.com server and put this(must be the first rule):
RewriteEngine On
RewriteRule .* http://newsite.com/ [R=301]
or
Redirect 301 / http://newsite.com/
Regards.

htaccess URL Rewrite not working after 301 redirect

I have the following url rewrite:
RewriteRule ^info/([^/\.]+)/?$ info.php?page=info&subpage=$1 [L]
Originally the parameters were the page id's i.e. 0-10.
I have now changed this so the URLs have more meaningful slug names to reflect the content.
I have now set up the 301 redirects, for example:
Redirect 301 /info/0 http://www.example.com/info/intro
But the problem is, the redirect doesn't go to the url rewrite (http://www.example.com/info/intro). Instead it shows the full url (http://www.example.com/info.php?page=info&subpage=0)
How can it get it to keep the rewrite?
Many thanks
As posted by LazyOne, the solution was to use RewriteRule:
RewriteRule ^info/0$ http://www.example.com/info/intro [R=301,L]

Apache redirect with GET variables

I would like to redirect all requests to a subfolder on down on a site. So:
http://thesite.com/oldfolder/whatever/anything.php?getvar_stuff
goes to
http://thesite.com/newfolder/
If I use the following .htaccess file:
RedirectMatch 301 /oldfolder http://thesite.com/newfolder/
.. the URL that returns is:
http://thesite.com/newfolder/?getvar_stuff
Don't want the "post_stuff", so I change the rewrite line to:
RedirectMatch 301 /oldfolder http://thesite.com/newfolder/?
.. the URL that returns is:
http://thesite.com/newfolder/?
Which is better, but I'd still love to lose that question mark. Is it possible?
It appears that the best way to do this is not using Redirect, but rather Rewrite:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/oldfolder/
RewriteRule ^(.*)$ http://thesite.com/newfolder/? [R=301,L]

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]