Rewrite rule to give 410 Gone for a specific URL doesn't work

Rewrite rule to give 410 Gone for a specific URL doesn't work - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, url-rewriting, 410-gone, , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I'm French.
A week ago, my website was hacked with the old version (http). The hack created 404 spams and I want to ensure they have "410 Gone" status.
My problem on the site is: https://www.example.com/aasption



I tried:



RewriteRule ^aasption - [G] 


in the htaccess. It doesn't work. What is going wrong?



UPDATE:



The problem is that I'm still getting a 404.



Example URLs that have been spammed:




  • www.example.com/aasption.asp?id=puma/puma-ambition-collant/prd/9723115?...

  • wwww.example.com/aasption.asp?search=puma&page=5



My .htaccess:



<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]
RewriteRule ^aasption - [G]
</IfModule>

Solution :

You've put your directive in the wrong place. It needs to go at the top of the .htaccess file, before the front-controller, not at end. By putting this code at the end, it's simply not going to do anything, because the preceding directives have already rewritten the URL for any request that does not map to a physical file.



The order of these directives is important.



For example:



# Send 410 Gone for any URL that starts "/aasption"
RewriteRule ^aasption - [G]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]
</IfModule>


You do not need to repeat the RewriteEngine On directive.


Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect