Forum Moderators: phranque

Message Too Old, No Replies

410 error if special characters in url

         

omax

1:13 pm on May 16, 2007 (gmt 0)

10+ Year Member



Hello
What I want to do : if the requested url has special characters like domain.com/page$.htm or &%^@~£ etc then return "gone"=410.The special character can be anywhere in the url.
To have in the htaccess file something like

RewriteRule ^check url here$ somepage.html [G,L]

Thanks.

jdMorgan

2:30 pm on May 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Create an unanchored negative character-group, listing the characters you want to accept:

RewriteRule [^\-a-z0-9/_.] - [NC,G]

"^" means "NOT" when used as the first character in a [group].

The hyphen is escaped as shown to avoid confusing the regex parser by making it think you're doing a range comparison. This isn't always necessary, but it is "safe."

[NC] makes the character-comparison case-insensitive.

There is no need to use [L] with [G], because [G] implies [L].

For more information, see the concise regular-expressions tutorial cited in our forum charter [webmasterworld.com].

Jim

omax

11:46 am on May 17, 2007 (gmt 0)

10+ Year Member



I read before asking some tutorials about htaccess - I created some rules , but it seems I missed the "^" sign part :-)

The line
RewriteRule [^\-a-z0-9/_.] - [NC,G]
doesn't work on my server - I get an internal server error .
but it works perfectly without the "\" :
RewriteRule [^-a-z0-9/_.] - [NC,G]
So, thank you very much Jim.