Forum Moderators: phranque

Message Too Old, No Replies

need help for a pattern

cannot get it working

         

BlueBlizz

12:59 am on Sep 26, 2009 (gmt 0)

10+ Year Member



Ik need a patern for the following:

different type of input:
aaa
aaa/
aaa/A1
aaa/A1/
aaa/yyy
aaa/yyy/A1
aaa/yyy/A1/
/aaa
/aaa/
/aaa/A1
/aaa/A1/
/aaa/yyy
/aaa/yyy/A1
/aaa/yyy/A1/

in all cases the part between starting / and /A1 or end must be selected.
aaa/yyy is the categorie path;
alle our products start with A1 (ie: A12345)
thus the selected part must be our categories:
aaa or aaa/yyy or even aaa/yyy/aaa/bbb
even with or without /A1-product at the end

I cannot get it.

^[/]?([A-Za-z0-9-/]*)[/]?[^A[0-9]]*

does not work.

g1smd

1:10 am on Sep 26, 2009 (gmt 0)

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



*** between starting / and .... ***

Half of those don't start with a slash.

I'm not understanding the exact requirement here.

jdMorgan

1:25 am on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about:

RewriteCond %1 ^(([^/]+/)?[^/]+)/?$
RewriteRule ^([^A]+)(A1)? /script/categorie=%1 [L]

The rule pattern captures everything up to the "A1" (if it is present) and the result is passed in $1 to the RewriteCond which captures everything up to the last slash (if in is present), and passes that result back for use in the RewriteRule substitution.

Or maybe just


RewriteRule ^([^/]+(/[^/A]+)?)(/A1)? http://www.example.com/script/categorie=%1 [L]

Neither method is tested, I'm just "thinking out loud" here...

I not sure why you think there's the possibility that the leading slash may or may not be present. Either it will never be there, or it will always be there, depending on where this code is located.

Jim

BlueBlizz

10:37 pm on Sep 26, 2009 (gmt 0)

10+ Year Member



Due to your sugggestions:
RewriteRule ^/?([^A1]*[^/]$)¦^/?([^A1]*)/$¦^/?([^A1]*)(/[Aa][0-9]{5}/[0-9]{4})¦^/?([^A1]*)(/[Aa][0-9]{5}) /${txt-file:$1$2$3¦}

this rule selects all categories like .../.../.../... (1 to many subcats) independent if there's a starting /
or if there's a product /A12345 at the end. and check the content in a text-map-file for matches.

(if use the tool 'Regex Coach' to check a syntax. Are you familiar with it? or do you use another one)

jdMorgan

1:01 am on Sep 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't use any tools... I just write the code.

Why do you think the leading slash may or may not be present?

Jim

BlueBlizz

10:14 am on Sep 30, 2009 (gmt 0)

10+ Year Member



Looking more detailed to the output:

It always show:
RewriteCond: input='/running/' pattern='.....' =>

there always is a started / for rewrite conditions.

Caterham

12:44 pm on Sep 30, 2009 (gmt 0)

10+ Year Member



there always is a started / for rewrite conditions.

Well, what do you input? There's always a 'Wednesday' for rewrite conditions if I'd use

RewriteCond Wednesday ^

The part in question is the rule-pattern; anyway it looks like you're continuing in a new thread [webmasterworld.com].

And as you can see

(3) applying pattern '^/?([^A1]*)/$' to uri 'running/'

There's no leading slash.

there always is a started / for rewrite conditions.

You're inputting %{REQUEST_URI} and that'd always start with a leading slash, otherwise your request would have died with a HTTP 400 earlier.

jdMorgan

6:20 pm on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So the question is, why does your pattern include "?" after the "/", making that slash optional?

The RewriteRule pattern should either start with a slash or not start with a slash, depending on where the code is located, but the presence or absence of a leading slash is not going change between requests -- it will either always be there or it will always not be there, depending only on where this code is located.

Therefore, including the regular-expressions "?" quantifier after the slash is a waste of processing power, even if it's only a "little waste." The problem is that lots of little time-wasters add up to a big time-waster, and can force you into an early server upgrade. So, "neatness counts" and you should code to your exact requirements, and not include *anything* in your code that you do not fully understand...

Jim

jd01

7:23 pm on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My guess is automation is the cause:
Regex Coach...

It's almost like the ToolBar issue with the 404 yesterday, only possibly worse. I haven't been reading in here too much lately, but this is the second time in a day I've seen a left-side-of-the-rule pattern begin with /?.

I just figured it was a coding error earlier, but now I'm starting to think people are using 'generators' or something like the OP mentioned and it's generating 'put it anywhere' (httpd.conf ¦ .htaccess) code, because of 'simplicity' and 'works', never-mind anything else...

ADDED: It's the First Two Times I've seen a pattern begin with /? and I wondered why too. It makes a bit more sense now... Automation = 'Think for the user, rather than asking where the code will be used.'

jd01

8:20 pm on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<extensionofmypreviouspost>
Not that you probably didn't already guess that Jim... I was just thinking it might be a new issue to tell people to watch out for more than anything.

Trying to work on the bluntness. :)
</extensionofmypreviouspost>

@BlueBlizz

not include *anything* in your code that you do not fully understand...

What jdMorgan said in bold x 2...

We're talking about stuff that breaks your site, can ruin your search engine rankings and can possibly break your server if you get it wrong, that's why it's a hidden file.

I recommend if you use any auto generation or tools, you compare it to your own knowledge. There's a bunch of tutorials and documentation in the Library [webmasterworld.com].