Forum Moderators: phranque

Message Too Old, No Replies

Returning 410 Errors for .asp URLs

         

Saudiqua

6:49 am on Aug 25, 2011 (gmt 0)

10+ Year Member



I have an issue where I want to return 410 errors for .asp URLs via my .htaccess file but I have no idea where to start, this is the current code I have, is there anyone out there that can help me?

RewriteCond %{REQUEST_FILENAME}!-U
RewriteRule \.asp$ - [G]


Please help, I suck with .htaccess... :(

lucy24

9:25 am on Aug 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Did you remember

RewriteEngine on

?

Warning from Apache [httpd.apache.org] about -U:
This uses an internal subrequest to do the check, so use it with care - it can impact your server's performance!


Further caution: 410 is supposed to be used for files that genuinely used to exist and no longer do. But if your rule is aimed at robots this is not a serious problem, because they will only come looking for files that they've been to before. Unless you forget to update all internal links.

You don't say what the problem is, so it's hard to come up with more specific help.

Saudiqua

9:38 am on Aug 25, 2011 (gmt 0)

10+ Year Member



Yes I did.

This is the complete .htaccess that I have at the moment.

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !^(.+)\.asp$
RewriteRule ^(.*)$ - [G]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA]

</IfModule>

lucy24

9:53 am on Aug 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Uhm, the Condition for your first rule says it only applies if the name does not end in .asp. I thought it was the .asp files that were supposed to get the 410. In fact the rule from your first post ought to work fine. No Conditions needed; the .asp is integral to the Rule.

What happens when you try it? If you type in any old garbage ending in .asp, you should get the 410 screen.

The <If... part looks as if you started with boilerplate htaccess from some outside source. Either you have mod_rewrite or you don't; find out before you start writing for it. (Do there exist Apache installations that don't have mod_rewrite? Ones from within the present century?)

Saudiqua

10:03 am on Aug 25, 2011 (gmt 0)

10+ Year Member



Thanks for the reply Lucy...

I'm basically working with an exisiting .htaccess file.

I'll change the <if.. part to be more up-to-date. I'll use the rule from my first post and see what happens, but its like the .htaccess file is not reading the code or something...not sure...

Will keep you posted...

Saudiqua

10:10 am on Aug 25, 2011 (gmt 0)

10+ Year Member



OK, this is what I'm working with now, but I still get 404 errors for URLs like [mydomain.com...]

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^(.*)\.asp$ - [G]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA]

</IfModule>

g1smd

11:49 am on Aug 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Dump the "ifModule" bits. You do not want your code to silently fail.

^(.*) is redundant, the entire pattern says "grab the entire path and file, then after the end of "everything" look for more stuff".

How can it? This is garbage, causes the parser to do thousands of "trial mataches", and massively slows your server.

Never use (.*) at the beginning or in the middle of a pattern.

Add the [L] flag to the RewriteRule.

RewriteEngine On
RewriteRule \.asp$ - [G]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php?url=$1 [QSA,L]


The -f and -d "exists" checks are VERY inefficient. Alter the (.*) pattern to be more specific OR precede these with a RewriteCond that disallows URL requests that never need to be rewritten so that the -f and -d checks nor the rest of the ruleset are not invoked for those requests.

Typically this will be something like

RewriteCond %{REQUEST_URI} !^(images|styles|scripts)/
RewriteCond %{REQUEST_URI} !\.(png|jpe?g|gif|pdf|zip|txt)$


or similar.

Saudiqua

11:56 am on Aug 25, 2011 (gmt 0)

10+ Year Member



I managed to get it working, seems it was my RewriteRule that was a problem, the RewriteRule that works was:

RewriteRule \.asp - [G,NC]

This returns a 410 server error for all .asp URLs.

Thanks to everyone who helped me :)

g1smd

12:07 pm on Aug 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Presumably you were using .ASP and not .asp then?

Did you make ALL of the other suggested changes?

Without the $ anchor you will also block requests that "contain" .asp not merely those that "end" in .asp.

Saudiqua

12:13 pm on Aug 25, 2011 (gmt 0)

10+ Year Member



No I was using .asp.

Did not make any of the other suggested changes but will definately look into it.

And I want to block all requests that contain .asp.

Thanks @g1smd :)

lucy24

7:51 pm on Aug 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



And I want to block all requests that contain .asp

The unanchored form works if you can be positive the sequence .asp will never occur anywhere else. Admittedly there are not many places it can occur-- I was going to suggest domain names like www.aspell.com or www.aspersions.com, but those are ignored in the Rule anyway. Conversely, you could have extensions in .aspx.

This is why it is essential to escape all periods. Otherwise you would be grabbing anything that contains "gasp" or "wasp" or /asperity or viper/asp/ or ... and so on.

g1smd

8:03 pm on Aug 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The suggested changes take your code from being something that "seems to work" for the limited amount of different inputs you have tried, to being a lot more robust in dealing with real life URL requests, even malformed ones.

holidayscalendar

10:41 am on Nov 19, 2011 (gmt 0)

10+ Year Member



If someone out there sees this can you help me with a similar issue, only with php instead of asp?

lucy24

11:26 am on Nov 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It's better to start a new thread addressed to your specific problem. Be sure to show your current code and explain exactly what the results are.