Welcome to WebmasterWorld Guest from 54.166.141.12

Forum Moderators: Ocean10000 & incrediBILL & phranque

410 multiple files except for two

     
3:49 pm on May 21, 2018 (gmt 0)

Senior Member from US 

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

joined:June 4, 2002
posts: 1872
votes: 3


How do I 410 multiple files except for two that have a similar setup? i.e., they all have keyword1 plus keyword2 and all letters are in lower case. The keyword1 is the same on all pages but the other keyword varies. There are no spaces or hyphens. The two pages I want to keep have the same format. Is there a way to exclude those 2 pages?

here is what I'm using for the 410's:

RewriteRule ^keyword1+[a-z]\.php$ - [G}

[edited by: Lorel at 4:18 pm (utc) on May 21, 2018]

5:12 pm on May 21, 2018 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 308
votes: 21


You can include a negated condition for each URL you want to exclude from the rewrite. For example:


RewriteCond %{REQUEST_URI} !^/first-url-to-exclude\.php$
RewriteCond %{REQUEST_URI} !^/second-url-to-exclude\.php$
RewriteRule ^keyword1+[a-z]\.php$ - [G]


The ! prefix (ie. "not") on the CondPattern negates the regex.

However, your RewriteRule looks incorrect (although maybe this is just a problem with your "exemplified" version)? For a start you had a curly brace closing the flags (looks like a typo). But also, this doesn't match two keywords. The "+" simply repeats the previous character and [a-z] just matches a single character. So, this "example" would match a URL of the form "/keyword1a.php" or "/keyword11111z.php" etc. Is that intentional?
7:16 pm on May 21, 2018 (gmt 0)

Senior Member from US 

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

joined:June 4, 2002
posts: 1872
votes: 3


Thanks for the exclusion rule. I've been checking a Regex Character Definitions list but didn't see that option.

Yes, the curly brace was a typo.

Re the Rewrite Rule I wrote out, I was hoping that I could specify a specific keyword (as most of these files all start with the same word). Is that possible?

The actual file name looks like this:

keyword1differentkeyword2.php

From what you said above it appears I need something more in my coding to specify any amount of characters and not just one. I can't find this is the Regex samples. Can you let me know how to do this?
8:06 pm on May 21, 2018 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11356
votes: 147


From what you said above it appears I need something more in my coding to specify any amount of characters and not just one.

the plus sign (+) after a character (class) or capture group means "1 or more".

i would suggest using something like this:
RewriteCond %{REQUEST_URI} !^/keyword1(keywordA|keywordB)\.php$
RewriteRule ^keyword1[a-z]+\.php$ - [G]

if possible, make the Pattern of the RewriteRule more specific.
9:28 pm on May 21, 2018 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 308
votes: 21


Thanks for the exclusion rule. I've been checking a Regex Character Definitions list but didn't see that option.


The ! (negation) prefix is not a regex-thing. It is a feature of Apache's mod_rewrite (and expressions). It negates the condition, whether the argument is a regex or not. (eg. It's common to see "!-f")
11:25 pm on May 21, 2018 (gmt 0)

Senior Member from US 

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

joined:June 4, 2002
posts: 1872
votes: 3


Thanks for the tips. That was one of the simplest URLs that I have to 410. I have another that has 4 or more keywords, one of which has a number. Is this the proper way to write this or is there a way to shorten it?

I don't need to use a specific keyword with this one:

word1-word2(with number)-word3-word4.php (some of the file names have more or less words, which will come after the first word/number combination but there is only one word with a 1 number character). These words are all separated by dashes.

RewriteRule ^[a-z]+-([a-z]+[0-9]{1})-[a-z]+-[a-z]+\.php$ - [NC,G}
8:37 pm on May 22, 2018 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11356
votes: 147


word1-word2(with number)-word3-word4.php (some of the file names have more or less words, which will come after the first word/number combination but there is only one word with a 1 number character). These words are all separated by dashes.

RewriteRule ^[a-z]+-([a-z]+[0-9]{1})-[a-z]+-[a-z]+\.php$ - [NC,G}

i would try something like this:
RewriteRule ^[a-z]+-[a-z]+[0-9](-[a-z]+)+\.php$ - [G]

(if you also want to match upper case or mixed case paths you can add the NC flag.)
10:19 pm on May 22, 2018 (gmt 0)

Senior Member from US 

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

joined:June 4, 2002
posts: 1872
votes: 3


Thanks Phranque. I wouldn't have though to put the dash within the parentheses.

It sure helps to understand how algebra works to figure out these combinations.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members