redirectmatch not picked up in htaccess - .htaccess

I try to redirect a ddos attacks. I use redirectmatch conditions, but somehow it is not working in my htacces. the code is
RedirectMatch 301 \d*\?_uw=\d* http://www.someurl.com
or
RewriteRule ^\d*\?_uw=\d* http://www.someurl.com [L,R=301]
None of above is working. I would like to match following urls where numbers are always changing 197831051715412?_uw=9351823359

You can use:
RewriteEngine on
RewriteCond %{QUERY_STRING} _uw=\d*
RewriteRule ^\d*$ http://www.someurl.com/? [L,R=301]
With this other last line:
RewriteRule ^ http://www.someurl.com/? [L,R=301]
You don't test file name (if they also use letters) only _uw=

Related

301 redirect from multiple url parameters

I'm trying to redirect any of these formats
mydomain.com/?main_page=products_new
mydomain.com/?main_page=products_new&page=2
mydomain.com/?main_page=products_new&disp_order=2
to this
mydomain.com/new-products
I have this working for only the first parameter. How can I ignore the remaining ones and match on anything that contains ?main_page-products_new ?
RewriteCond %{QUERY_STRING} ^main_page=products_new [NC]
RewriteRule ^(.*) /new-products? [L,R=301]
Apache supports RedirectMatch
RedirectMatch 301 ^main_page=products_new.*$ /new-products?$1

Replace word within url and redirect

I am trying to replace word with another word in url and redirect but its not wokring due to query string.
Here is eg. Here is the url and i want to redirect it
https://www.custesitetest.com/test_calculator.php?tf=to&loc=staines
to
https://www.custesitetest.com/autoqoute?tf=to&loc=staines
RedirectMatch ^/test_calculator.php/(.*)$ https://www.custesitetest.com/autoquote/$1
You can use this rule in your root .htaccess:
RedirectMatch 301 ^/test_calculator.php?$ /autoquote
Try it like this with mod_rewrite,
RewriteEngine On
RewriteCond %{REQUEST_URI} ^test_calculator.php
RewriteCond %{QUERY_STRING} ^(.+)
RewriteRule ^ autoquote?%1 [R=301,L]

How redirect urls with special url?

I want to redirect this type url to my home page
http://www.mywebsite.com/index.php?showuser=
to
http://www.mywebsite.com/
Can I do this with .htaccess? How to do it. I tried this but works nothing.
redirectMatch 301 /index.php?showuser= http://www.mywebsite.com
And
RedirectMatch 301 /index.php\?showuser\= http://www.mywebsite.com
You can't match against the query string in the RedirectMatch regex. You need to use mod_rewrite and the %{QUERY_STRING} variable:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^showuser=
RewriteRule ^index\.php$ /? [L,R=301]
Neither Redirect or RedirectMatch can match the query string. The ? in RedirectMatch actually means "the previous character 0 or 1 times", and would be matched against "index.php". Please note that you are not using the dot correctly too.
You can solve this by using mod_rewrite. Make sure that it is enabled, and that you allow override of FileInfo. Then use the following directives:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^showuser=$
RewriteRule ^index\.php$ / [R,L]
Change [R] to [R=301] if you wish to make the redirect permanent after testing everything works as expected.

url redirect exact match including params

i would like to make a 301 redirect and from an old website using the exact exact url with no extra parameters.
example:
/en-direct.php?page=7
to go to:
http://www.example.org/news/
and page:
/en-direct.php?page=8
to go to:
http://www.example.org/awesome-but-totally-different-page/
i used:
redirectMatch 301 ^/en-direct.php$ http://www.example.org/different-page/
redirectMatch 301 ^/en-direct.php?page=7$ http://www.example.org/news/
redirectMatch 301 ^/en-direct.php?page=8$ http://www.example.org/awesome-but-totally-different-page/
however: i get http://www.example.org/different-page/ every time with all the parameters from the redirect page (example - http://www.example.org/different-page?page=7 )
any help will be much appreciated.
In order to match against the query string, you need to use mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page=7($|&)
RewriteRule ^en-direct\.php$ http://www.example.org/news/ [L,R=301]
RewriteCond %{QUERY_STRING} ^page=8($|&)
RewriteRule ^en-direct\.php$ http://www.example.org/awesome-but-totally-different-page/ [L,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^en-direct\.php$ http://www.example.org/different-page/ [L,R=301]

htaccess redirect with variable added to end

So, I can't quite figure out the redirect for this. I'm moving a subdomain and all of its content to another domain, but want to add a variable to the end of every url so that it ends up like so:
http://old.domain.com/products/something-or-other.html
turns into
http://www.newdomain.com/products/some-or-other.html?p=abc
I tried this but it doesn't add the variable unless you're only on the root of the domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old.domain.com$
RewriteRule (.*)$ http://new.domain.com/$1/p_ig=abc [R=301,L]
EDIT (figured it out with a RedirectMatch instead):
RedirectMatch 301 ^/(.*)/(.*)$ http://new.domain.com/$1/$2?p_ig=abc
You can try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old\.domain\.com$ [NC]
RewriteRule ^ http://new.domain.com${REQUEST_URI}?p_ig=abc [R=302,L,QSA]
Once you verify that it's working fine then change R=302 to R=301.

Resources