FilesMatch htaccess directive syntax.
-
Would you look at this code and tell me why it won’t work. My htacess checker says the syntax is ok. This is code that worked until about 2 to 3 weeks ago.
<FilesMatch "\.(store + html)$"> RewriteRule ^410\.shtml$ [R=G,L] </FilesMatch>
-
Thanks for creating a new thread topic for this.
I am not exactly sure what you are trying to match. I get the .store part but not the html part. Post the string that you are trying to match.a + sign means match 1 or more of the proceeding token
so you are saying match “s” or “t” or “o” or “r” or “e”\.(store)+
if you put the + sign after the group (store) then the + sign will match the entire “store” group/word.Actually .store seems a bit odd since that is not a valid file extension that I am aware of. The FilesMatch and Files directives are only used for matching files/filenames. ie example.html, example.png, etc. So what exactly is “.store”?
http://httpd.apache.org/docs/current/mod/core.html#filesmatch
The
<FilesMatch>directive limits the scope of the enclosed directives by filename, just as the<Files>directive does. However, it accepts a regular expression.There is a .DS_Store file extension, but you typically delete these from your website files and do not want to do anything with or to them.
When using [G], an [L] is implied – that is, the response is returned immediately, and no further rules are evaluated.
In plain english that means that if you use the G flag then you do need to also use the L flag. Also the G flag is used alone the same as the F flag so you would not use the R flag.
RewriteRule ^410\.shtml$ [G]Oops and you also want to use the “-“.
RewriteRule ^410\.shtml$ - [G]And for case insensitive you can use the NC flag
RewriteRule ^410\.shtml$ - [G,NC]\.(store+)hmm this works as long as you do not have a whitespace after store since you would be matching whitespaces too. Unless of course that is what you wanted: “.store [whitespaces here]”. Interesting. I was not aware that this was valid usage. I prefer to use \s with a range so that I do not make mistakes: \.(store)\s{1,3}Correction:
\.(store +)would match: .store and 1 or more whitespaces after “.store” – time to hit the sack seeing double at this point. πThe seeing double I understand very well.
The URI I am trying to match looks like this
/store/anypage.html (store was used as a folder) (anypage could be any combination of letters, numbers or punctuation)
ie. /store/viagra.html or /store/xga.htmlThis is to finish cleaning up a pharma hack on my old html site from 2010 which Google still brings up because there are websites out there I can’t control pumping out this stuff every so often.
I didn’t know about the – so that is a helpful reply.
How about for a wild card to .html supposedly syntax is ok.
<FilesMatch “/store/+(.*)\.html$”>
RewriteRule ^410\.shtml$ – [G]
</FilesMatch>The problem I have with any of this is I keep getting 404 instead of the transfer to the 410 response.
Since “store” is not a filename and is a path/URI then it cannot be used in the FilesMatch code. You actually do not need to use FilesMatch for this. Does the /store/ folder still exist or does it no longer exist anymore?
If you are only handling .html files then you can do this, but this would affect all .html files on your website so if you have any legitimate .html files then they will also be affected
<FilesMatch "\.(html)$"> RewriteRule ^410\.shtml$ - [G] </FilesMatch>the store folder does not exist on my site nor do any of the html files. They do exist on other websites using my fly-fishing-colorado.com/store/junkpharma.html name to try and get orders I suppose.
Google picks them up and thinks they are coming from my site so the only way I see to combat it is to tell Google they are gone and not coming back. Which is true for my site as an originating site. What makes this a nasty hack is I can’t stop the other sites from using my name. A hacker is not going to pay any attention to any DCMA or any other thing I send them.
I have no valid html files anymore on fly fishing colorado. It is totally WP now. But I bet the code above will produce a 404 error and not a 410. I will make a video for you to show what is happening.
If you will recommend a good htaccess book or manual, I will study this more. So far I have not found a really good complete tutorial online.
Ok then here is what I think the best and simplest thing to do would be since the URL’s are external URL’s that are basically bad URL’s so you just treat them like a normal external bad URL and redirect them somewhere else so that google does not see them as 404 errors which they actually are since the URI does not exist on your website. No point in making this more complicated then it needs to be.
RedirectMatch 301 ^/store/(.*)$ http://example.com/Just tried your html code and it produces a 404 not a 410. I believe my host has messed up the htaccess rules portion of their apache module or this stuff should work. A Redirect 301 or 410 still work but not any custom rewritw rule I have tried.
A level II tech suggested making a php page with a
header( “HTTP/1.1 410 Gone” ); //google would interpret this one as an actual 410 error. I mean what kind of solution is that to an htaccess rewrite rules not working problem. Yes it will work but why do this when I should be able to do it with htaccess.What does that tell you about how apache is working and htaccess is working on my host.
The topic ‘FilesMatch htaccess directive syntax.’ is closed to new replies.