Are you getting lots of 404 errors in the log because of some urls having patterns like ” ++liker.profile_URL++ ” ? How to reduce 404 errors created by ++liker.profile_URL++ ? Here is the solution to stop those 404 errors and convert those urls to result in 301 permanent redirects to your homepage.
Problem:
Some days back, when I saw the log created by Better WP Security plugin installed on my blog, there were a lot of 404 errors because of some weird URLs something like this:
- subharanjan.com/subharanjan.com/subharanjan.com/remove-or-override-functions-attached-to-a-specified-filter-hook/++liker.profile_URL++
- subharanjan.com/++liker.profile_URL++
I tried to find out about this and seems like this is a link dropping spambot. I am not sure what exactly it does but here is a solution to stop this.
Solution:
- Open you .htaccess file.
- Add these lines below into your .htaccess file which can be found at the root of your WordPress installation.
# -------- find and redirect to index.php ---------------------------------------
Add these lines before the lines( url rewrites ) added by WordPress for permalink support. It should look like this:
RewriteCond %{REQUEST_URI} ^(.*)++liker.profile_URL++* [NC]
RewriteRule ^(.*)$ /index.php [R=301,L]
# -------------------------------------------------------------------------------# -------- find and redirect to index.php ---------------------------------------
RewriteCond %{REQUEST_URI} ^(.*)++liker.profile_URL++* [NC]
RewriteRule ^(.*)$ /index.php [R=301,L]
# -------------------------------------------------------------------------------
# BEGIN WordPressRewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]# END WordPress
- Save the .htaccess file and check by accessing one of the urls having ++liker.profile_URL++ and see if it results in a 404 Page not found error OR simply redirects to your home page.
Explanation of the above htaccess code snippet:
RewriteCond will be looking for the pattern “++liker.profile_URL++” in the requested urls. Once it finds that piece of text in the requested url, it will redirect the request to home page in place of creating a 404 error as mentioned in the RewriteRule section.
RewriteRule defines a particular rule.
The first string of characters after RewriteRule defines what the original URL looks like.
The second string after RewriteRule defines the new URL. This is in relation to the document root (html) directory. / means the html directory itself, and subfolders can also be specified.
- ^ begins the line to match.
- . stands for “any non-whitespace character”
- * means that the previous character can be matched zero or more times.
So, ^uploads.*$ matches uploads2009, uploads2010, etc.
^.*$ means “match anything and everything.” This is useful if you don’t know what your users might type for the URL. - () designates which portion to preserve for use again in the $1 variable in the second string. This is useful for handling requests for particular files that should be the same in the old and new versions of the URL.
- [NC] matches both upper- and lower-case versions of the URL.
- [R=301,L] – this performs a 301 redirect and also stops any later rewrite rules from affecting this URL. It’s on the same line as RewriteRule, at the end.
Source: https://kb.mediatemple.net/questions/85/Using+.htaccess+rewrite+rules#gs
Leave a Reply