Block 'kw=' Query String - .htaccess

I keep getting nonsense hits to my site like:
myurl.com/?kw=antivirus*protection
myurl.com/?kw=a+casino
myurl.com/?kw=.confused.com
myurl.com/?kw=whatevernonsense
Also, if it matters, it is a self-hosted Wordpress site. I've tried many permutations to the following, but it isn't working:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} kw
RewriteRule ^(.*)$ - [F,L]
</IfModule>
Edit: I've tested the above code in a separate directory, and it works fine. Below is the Wordpress chunk I've narrowed it down to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} kw
RewriteRule ^(.*)$ - [F,L]
</IfModule>
# Use PHP5.3 Single php.ini as default
AddHandler application/x-httpd-php54s .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

I was able to fix this by adding the following to the WP chunk of the .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# These 2 lines block any request coming in with `/?kw=`
RewriteCond %{THE_REQUEST} \s/+[^?]*\?kw=
RewriteRule ^ - [F,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Related

redirect missing pages - why isn't this working?

I have this in my .htaccess file. I think it should redirect http://bashof.org/Hall_of_Fame_1980.html - to -> http://bashof.org/category/inductees/1980/
Anyone know why it isn't working?
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteEngine on
RewriteRule ^Hall_of_Fame_1980\.html category/inductees/1980/ [R=301,NC]

How to make .htaccess redirect to subdomain with parameters

How do I make a redirect from all pages following /react-api, such as:
www.example.com/react-api/workout?id=123
www.example.com/react-api/another-site/?id=321
to:
app.example.com/react-api
and I wan't to keep the folder and parameters.
This is what I have tried:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^react-api/(.*) app.example.com/$1 [R=301,L]
</IfModule>
# END WordPress
But it doesn't work.
Please help
You need to use http:// in your target URL and also change order of your rules and keep redirect rule at the top:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^react-api(/.*)?$ http://app.example.com%{REQUEST_URI} [R=301,NE,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

.htaccess Redirect Rewrite Rule

I'm struggling with some redirects on the redesign of a website.
The old one got several urls like this:
http://www.example.com/sitegroup/pages/GA/GA_Be.shtml
And I want to redirect this to:
http://www.example.com/sitegroup/garten-und-landschaftsbau/#gartenforum-ideengarten
I tried it with the following rewriterule:
RewriteRule ^/?pagesGA/GA_Be.shtml$ http://www.example.com/sitegroup/garten-und-landschaftsbau/#gartenforum-ideengarten$1 [R=301,L,NE]
But I just can't get it working.. I'm really new to .htaccess rewriterules.
Also some of the old pages got links like this:
http://www.example.com/sitegroup/pages/GA/GA_Be.shtml?navid=15
But the ?navid=15 isn't doing something(just highlighting the menulink) so I thought just redirecting the GA_BE.shtml should be enough. Am I correct?
Here is the complete .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sitegroup/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sitegroup/index.php [L]
</IfModule>
# END WordPress
RewriteRule ^/?pagesGA/GA_Be.shtml$ http://www.example.com/sitegroup/garten-und-landschaftsbau/#gartenforum-ideengarten$1 [R=301,L,NE]
Thanks in advance!
You should put your RewriteRule before Wordpress Dispatcher:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sitegroup/
RewriteRule ^pages/GA/GA_Be\.shtml$ http://www.example.com/sitegroup/garten-und-landschaftsbau/#gartenforum-ideengarten [R=301,L,NE]
RewriteRule ^pages/GA/GA_Bg\.shtml$ http://www.example.com/sitegroup/garten-und-landschaftsbau/#gartenplanung-landsc‌​haftsplanung [R=301,L,NE]
RewriteRule ^pages/GA/GA_En\.shtml$ http://www.example.com/sitegroup/garten-und-landschaftsbau/#erdsondenbohrung-erd‌​waerme [R=301,L,NE]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sitegroup/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sitegroup/index.php [L]
</IfModule>
# END WordPress
Otherwise the request will first be handled by the Dispatcher and never reach your rule.

301 permanent redirect not working (WordPress)

I'm trying to redirect all requests to a preview site to a different site. I'm not sure why this is not working. I'm not being redirected when I click the link.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^site.preview.com$ [NC]
RewriteRule (.*) newsite.com/$1 [L,R=301]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Answer is to remove the ! in the RewriteCond as this says only rewrite it if the the url is not equal to site.preview.com but I want it to redirect if that url is entered.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.preview.com$ [NC]
RewriteRule (.*) newsite.com/$1 [L,R=301]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

i want 301 redirection to multiple pages

i want to change urls of my website, but there many pages, so i cant change them manually.
so i need to change it from htaccess file.
i want to change the below url
http://demos.beusoft.com/ccjk/resource/arabic-translation-services/
with the
http://demos.beusoft.com/ccjk/arabic-translation-services/
i am using wordpress.
this is whole code ....
# BEGIN WordPress
RewriteEngine On
RewriteRule ^ccjk/resource/([^/]+)/$ demos.beusoft.com/ccjk/$1 [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ccjk/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ccjk/index.php [L]
</IfModule>
# END WordPress
please help, how to rewrite the url from the htaccess file.
Try this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ccjk/
RewriteRule ^resource/([^/]+)/$ http://demos.beusoft.com/ccjk/$1/ [L,R=302]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ccjk/index.php [L]
</IfModule>
# END WordPress

Resources