RegEx string error

 
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting
View previous topic :: View next topic  
Author Message
logikal
-


Joined: 20 Apr 2002
Posts: 19

PostPosted: Sun Jan 21, 2007 9:15 pm    Post subject: RegEx string error Reply with quote

Hey Aprelium,

Thanks for finally invoking the url-rewrite feature. It's awesome! I have one question about a regular expression I'm attempting to use:

The following expression isn't quite working, and I'm wondering what I'm doing wrong.

If someone types /wiki/page_name, then they should be redirected to /_home/index.php?page=wiki&name=page_name or, equally, /_home/index.php?page=wiki&name=page_name&do=&id=.

If someone types /wiki/page_name/edit, then they should be redirected to /_home/index.php?page=wiki&name=page_name&do=edit.

Code:
^/wiki([^/].*){0,3}$


internally redirect:
Code:
/_home/index.php?page=wiki&name=$1&do=$2&id=$3


Any ideas as to what's causing this to break? My guess is that it's something about the regex not liking [^/]...
Back to top View user's profile Send private message
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Mon Jan 22, 2007 2:27 am    Post subject: Reply with quote

I would suggest logging the URL rewriting. This will give you many clues as to why it might not be working right. See http://localhost:9999/hosts/host@0/edit/urlrewrite/advanced/edit.

Put this rule in first:
Code:
^/wiki/(.*)/edit

Redirect to
Code:
/_home/index.php?page=wiki&name=$1&do=edit
Be sure to set 'Next Action' to 'Stop matching'.

Put this rule in second:
Code:
^/wiki/(.*)

Redirect to
Code:
/_home/index.php?page=wiki&name=page_name



As to why your code didn't work, the problem is in the brackets. It's treating the caret (^) as a literal value, not the identifier that is translated "begins with".

/wiki^/the_page_name would match with your RegEx.
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
logikal
-


Joined: 20 Apr 2002
Posts: 19

PostPosted: Mon Jan 22, 2007 3:14 am    Post subject: Reply with quote

Thanks, Stephen... I'll give it a try :wink:
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Mon Jan 22, 2007 2:00 pm    Post subject: Re: RegEx string error Reply with quote

logikal,

The problem is that your Regular expression defines only a single backreference $1 (there is only a single pair of brackets). $2 and $3 will always be empty.

If our guess is right, you'll have to change the regular expression to;

Code:
^/wiki(/([^/]*)(/([^/]*)(/([^/]*))?)?)?$


The rediret to value should also be updated to:

Code:
/_home/index.php?page=wiki&name=$2&do=$4&id=$6


By the way, tunring URL rewriting debugging/log on and testing your regex on http://www.regextester.com/ could help a lot when creating new rules.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
logikal
-


Joined: 20 Apr 2002
Posts: 19

PostPosted: Tue Jan 23, 2007 1:07 am    Post subject: Reply with quote

Ah, that makes total sense. I was assuming regex allowed "looping" of sorts...

Hey man, I thought I'd say congratulations. I've stuck with Abyss since the beginning, and it's good to see that you're finally starting to get the recognition you deserve. Abyss is a rare gem, and it's cool to see that it's still freely available to anyone. Unlike most software, Abyss only gets better over time.

-Matt
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Tue Jan 23, 2007 2:56 pm    Post subject: Reply with quote

logikal,

Thanks for your compliments.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group