We have an issue where spammers are subscribing to all our feeds.
I already disabled all feeds via a function, as well as using a plugin.
Each day they still appear in our logs with thousands of entries.
For example:
/leaderboard/feed/index.php
/leaderboard/feed/
/some-category/feed/
Is there any way to block access to all visitors querying /feed/ or anything containing the word "feed" in the URL via .htaccess, and deny them access to the site?
Yes rewrite rules can do that:
RewriteEngine On
RewriteRule ^feed/ - [NC,F]
This will give forbidden error for every URI that starts with /feed/
Related
I have been unpublishing old pages on my website. To avoid 404 pages, I'd like to redirect these pages to a generic page.
So for example this page:
https://www.portal-gestao.com/artigos/7380-7-t%C3%A1cticas-de-sobreviv%C3%AAncia-%C3%A0-crise-nas-vendas.html
Should redirect to:
https://www.portal-gestao.com/artigos/
I'm not very skilled with .htaccess or regular expressions, I've bee trying to redirect the pages with:
RewriteRule ^artigos/(.*)$ /artigos/$1 [R=301,L]
But something isn't working, can anyone help?
Late information... the site uses a Joomla CMS. See the UPDATE below.
To redirect requests for physical files that no longer exist you need to actually check that the file no longer exists, otherwise it will indeed "redirect everything" (as mentioned in comments).
For example, to redirect any requests of the form /artigos/<something>, that do not map to physical files, to /artigos/ you can do the following:
RewriteEngine On
REwriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(artigos/). /$1 [R=302,L]
The $1 backreference simply prevents you having to repeat the directory name.
The first condition that checks against the REDIRECT_STATUS environment is intended to ensure that only direct requests are redirected. This is probably only required if you are still on Apache 2.2 (as opposed to 2.4) since mod_dir will execute first, rewriting the redirected request to index.php (if it exists) and causing a rewrite loop. On Apache 2.4, mod_dir executes later.
Test with a 302 and only change to a 301 when you are sure it's working OK - to prevent caching issues.
You will need to clear your browser cache before testing.
However, a 404 would generally be a better response. The search engines will likely see the redirect to a common root as a soft-404 and users are more likely to be "confused" when they don't see the information they requested.
RewriteRule ^artigos/(.*)$ /artigos/$1 [R=301,L]
By itself, this would result in a redirect loop, as it simply redirects to itself.
UPDATE: it's not a file, it is an article in a Joomla CMS
If valid URLs do not map to physical files then you can't do this in .htaccess. In your case, a valid URL is determined by the Joomla CMS (as stored in the Joomla database). .htaccess is processed at the very start of the request, before control passes to PHP/Joomla. Directives in .htaccess can only look at the HTTP request and the physical filesystem.
Joomla uses a front-controller pattern. All URLs, that do not map to physical files (to exclude static resources like CSS, JS and images), are internally rewritten to index.php (the "front-controller"), this effectively "routes" the URL and decides what content should be returned.
What you are asking could only be done on a static website where URLs map to physical files on the file system.
You need to perform this redirect in Joomla itself, when Joomla has determined that the requested URL does not exist. (This is actually more efficient anyway as you only need to execute your code after a 404 has been determined, rather than on every single request, as it would be if you used .htaccess.)
So I have this website: www.example.com, which in the past would redirect the clients to www.example.com/subdir
Now I updated the whole site, and the subdirectory doesn't exist anymore, and I want the main domain to be the root. The problem is that many clients have cached the url with the subdomain included, so I need a redirection rule to route www.example.com/subdir to www.example.com.
I tried this:
RewriteRule ^subdir/(.*)$ $1
which works if I enter www.example.com/subdir/ with the last slash
but if I access www.example.com/subdir without last slash it won't do the job.
How can I make it work?
Change your rule to this:
RewriteRule ^subdir(?:/(.*))?$ /$1 [L,NC,R=301,NE]
It is important to use R=301 here so that all clients and search engines eventually move to new URL rather than keep using duplicate URL for the same content (bad SEO).
Via Apache, is it possible to exclude access to my site if a particular page request www.mysite.com/this_page/ is made? The referrer IP address changes.
I realize that I can "catch" this request in my code and give back an error page, but I'd prefer for the request to never make it to my actual code. I can also just remove the page, but then my site would return its "page not found" page. So, still a page.
My host is Webfaction and I use Django. So it's Apache.
The reason is that I am seeing some weird activity to this particular page. For the curious, I am getting requests for this page about 20 times a day in bursts of 1-3 requests in 2 seconds. The IP addresses are Ukrainian. The referrers are mostly various Ukrainian websites, which seem real enough, but they do not contain an actual link to my webpage.
I don't think blocking a whole country is a good idea, but here's how to do it.
First, get a list of CIDRs of the country in question. For most countries, it will be a large list. One place to get that would be http://www.find-ip-address.org/ip-country/. Then, merely put those into an .htaccess or Apache config file:
<Location /this_page>
order allow, deny
deny from 5.1.0.0/19
deny from 5.22.156.0/22
deny from 5.34.176.0/21
deny from 5.53.112.0/21
deny from 5.56.24.0/21
deny from 5.57.64.0/21
deny from 5.58.0.0/16
deny from 5.83.16.0/21
deny from 5.104.32.0/19
deny from 5.105.0.0/16
#...
</Location>
(Leading whitespace is optional, .htaccess files don't need Location tags if you're happy blocking the whole directory.)
The above config keys on the client IP rather than the IP of the host of the referring link. That part is much harder to do, though perhaps keying on the Ukrainian TLD would be sufficient:
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^https?://[^:/?#]*\.ua[:/?#]
RewriteRule ^/this_page - [F,L]
(Note that %{HTTP_REFERER} has no double Rs. The spec was misspelled, my config above was not.)
If you're getting slammed by high volume, you might want to consider dropping the connections at the firewall level rather than Apache. Again, that would be by client rather than by referrer.
for
joomla 1.5.26 website
running virtuemart 1
and SH404SEF 2.5.0.1040 enabled.
"Google Ads" urls returned to the site from a google campaign are causing a redirect loop:
here is an example:
http://www.brand-it.co.il/%D7%94%D7%93%D7%A4%D7%A1%D7%94-%D7%A2%D7%9C-%D7%9B%D7%9C%D7%99-%D7%9B%D7%AA%D7%99%D7%91%D7%94/%D7%94%D7%93%D7%A4%D7%A1%D7%94-%D7%A2%D7%9C-%D7%A2%D7%98%D7%99%D7%9D.html/?gclid=CKyLgNSjxbkCFbHKtAoaaaaaa
i upgraded the SH404SEF and isolated the problem to a trailing forward slash after the .html part of the url
so instead of this part .html/?gclid=
i remove the slash like this .html?gclid=
and it works fine:
http://www.brand-it.co.il/%D7%94%D7%93%D7%A4%D7%A1%D7%94-%D7%A2%D7%9C-%D7%9B%D7%9C%D7%99-%D7%9B%D7%AA%D7%99%D7%91%D7%94/%D7%94%D7%93%D7%A4%D7%A1%D7%94-%D7%A2%D7%9C-%D7%A2%D7%98%D7%99%D7%9D.html?gclid=CKyLgNSjxbkCFbHKtAoaaaaaa
so my question is: how to keep the original url indexed and create an internal redirect from the non-working url to the working one ? using .htaccess ?
thanks
You can try this rule:
RewriteEngine On
RewriteRule ^(.+?\.html)/$ /$1 [L,NC,NE,R=301]
I have updated my website to now use the codeigniter framework my new urls are like the following example.com/index.php/home/page/page-title
The old urls are example.com/index.php?option=com_content&view=article&id=249
Ideally I want to do a redirect for all links formatted in the old way to the new links but there are a lot of pages on the website and the titles/id do not match.
I do not want to write an individual rule for every page. eg
Redirect 301 /oldpage.html http://www.example.com/newpage.html
I do not mind having all the wrongly formated urls be redirected to the home page/404 page if this easier.
I can see this requires a more complicated rule that uses regex something I have never been very good at.
Any help appreciated
Thanks
The server doesn't know which ID may match a given title. You will have to handle these cases in CodeIgniter. Build a table with all old IDs and new URIs. Write a script that handles these requests and does the redirect.
Example (I haven't touched CI recently):
.htaccess
# parameter 'id' followed by a '=' followed by a number
RewriteCond %{QUERY_STRING} id=(\d+)
RewriteRule ^ /redirector/url/%1? [L,R=301]
CodeIgniter
Redirector could be a CI class, that looks into url, validates it as a positive integer, searches the database for a matching new URI and sends a Location header.
Try the RewriteMap directive. See http://httpd.apache.org/docs/2.0/misc/rewriteguide.html for details.