Welcome to WebmasterWorld Guest from 54.198.106.21

Forum Moderators: Ocean10000 & incrediBILL & phranque

RegEx help

     
3:18 am on Jun 6, 2017 (gmt 0)

Moderator from US 

WebmasterWorld Administrator keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:8995
votes: 409


They both result in the desired 410 Gone server response. Any advantage to the longer version?

RewriteRule ^example.html$ - [G]
RewriteRule ^example-widgets.html$ - [G]

RewriteRule ^example(-widgets)?.html$ - [G]
4:35 am on June 6, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13841
votes: 485


Config or htaccess? If it's in htaccess, the RegEx in the single-line version has to be recompiled on every request. Now, whether this creates a heavier load on the server than the alternative task of processing two separate RewriteRules... There may exist benchmark studies of the time and CPU load involved, but to some extent it's going to be specific to the current server. And I strongly suspect (as I'll bet you do too) that the difference in normal circumstances will be insignificant. So you're better off using whichever form you, personally, will feel most comfortable working with.

You will, of course, say \. for . because this is the rare case where it actually makes a difference. With a pattern expressed as "example.html", using dot (= any character) rather than \. (= literal period), a request for "example-widgets.html" will continue to match the pattern for one character longer than it ought to--and then just watch those picoseconds adding up.

If you go with the two-rule version, list the two pages in order of likelihood-to-be-requested.

Now, depending on what, exactly, "example" stands for, you may have a third and definitely more efficient option:

RewriteRule ^example - [G]
without closing anchor.
4:55 am on June 6, 2017 (gmt 0)

Moderator from US 

WebmasterWorld Administrator keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:8995
votes: 409


This is htaccess. The servers I use don't face the public (just your servers... he he)
RewriteRule ^example - [G]

without closing anchor.
Yup, that's the one. Short & covers several file types that are also gone. I was unsure of how liberal I could be with the regex for a 410. So there's no more negotiation restraints than on any other rule huh? It's not too often I use a 410.

Much grass
5:04 pm on June 6, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13841
votes: 485


the regex for a 410

A pattern is a pattern and a flag is a flag and never the twain shall meet.
Oh. Wait. Wasn't he actually saying that the twain meet all the time? Never mind then.

<digression>
The question made me think of my real-life version, which involves a directory along the lines of
/artists/john.html
/artists/john_files/{buncha-jpgs-here}
/artists/mary.html
/artists/mary_files/{buncha-jpgs-here}
et cetera. By and by when it came time to remove one person from the site (we didn't kick him out, he died) the rule was thriftily expressed as
RewriteRule ^artists/richard - [G]
and that's all the visitor needs. So I know from experience that it works.
</digression>
7:48 pm on June 6, 2017 (gmt 0)

Senior Member

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

joined:Aug 30, 2002
posts: 2602
votes: 89


The conditional version may require more processing. Simple RegExps are generally processed quicker. It might not have any performance impact on a low traffic server though.

Regards...jmcc
9:12 pm on June 6, 2017 (gmt 0)

Moderator from US 

WebmasterWorld Administrator keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:8995
votes: 409


Thanks jmccormac
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members