Closed Thread Icon

Preserved Topic: Regular Expressions in Perl5 (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=21068" title="Pages that link to Preserved Topic: Regular Expressions in Perl5 (Page 1 of 1)" rel="nofollow" >Preserved Topic: Regular Expressions in Perl5 <span class="small">(Page 1 of 1)</span>\

 
Blaise
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2003

posted posted 12-02-2003 00:17

Hi guys,

I'm delving into the unkown here trying to use urlRewriteFilter ,
it's a java webbapplett that works almost the same way that Apache mod_rewrite works,
basically it allows you to rewrite URLs, and this is what I want to do.

It uses regular expressions to filter and manipulate your URL, and regular expressions
are pretty Alien to me, I was wandering if anyone out there could put me on the right track
with creating one.

I've got a url that could be something like...

code:
www.mysite.com/games/flash/happy.htm

or it could be

code:
www.mysite.com/fun/sport/flash/cups.htm

what I want to do is to remove the flash from the URL and still have the page load correctly.

Here's what I have so far...

code:
<rule>
<from>/Flash/(.*)</from>
<to>/$1</to>
</rule>

But this doesn't load the pages correctly, which I think is strange because I'm not requesting that it redirects (am I?).

Any help or pointers would be greatly appreciated.

Cheers,

Blaise.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 12-02-2003 02:59

Blaise: I'm not sur how this works but I would have thought you'd need to add in the "/fun/sport" bit of the URL like:

code:
<rule>

<from>/fun/sport/Flash/(.*)</from>

<to>/fun/sport/$1</to>

</rule>



but as I say I don't know very much about this - if this was mod_rewrite I'd be wary of haivng the directory and URL structure so similar as it might go into a loop (can't see why it would here but......).

___________________
Emps

The Emperor dot org

Blaise
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2003

posted posted 12-02-2003 04:44

Hi Emps, thanks for the reply,

Having /Flash/(.*) doesn't cause any problems when I run it, I think it's because it just searches for that part in my URL and then substitues it with whatever is in the <to> clause.

I've written out the procedure of what needs to be done in English, perhaps this will help anyone who wants to help me

1. If request contains "Flash" then let it pass
2. If request contains no trailing slash and request does not end in filename then append /Flash/
3. If request contains trailing slash then append Flash/
4. If request ends with filename then insert either "/Flash" or "Flash/" before filename

This is to make sure the page loads correctly, but then I need to remove the "/Flash" from the URL for display in the address bar.

Any ideas?

Cheers,

Blaise


hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 12-03-2003 18:09

I'm not familiar with the urlRewriteFilter. Your subject line said Perl regex so I'll answer this as if you were writing in Perl.

I don't think the you can do what you described in your last post with a single regular expression.

In perl I'd say something like:

code:
if       ($url =~ m:/Flash/: )             { next }
elsif (-d $url and $url !~ m:/$ : ) { $url .= "/Flash/"; }
elsif (-d $url and $url =~ m:/$ : ) { $url .= "Flash/"; }
else { $url =~ s : ([^/]+)$:Flash/$1:; }



-- not necessarily stoned... just beautiful.


[This message has been edited by hyperbole (edited 12-03-2003).]

treeleaf
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Dec 2003

posted posted 12-06-2003 21:07

Hi,

If I understand it correctly, you are using something similar to perl re to parse the variables.
Here is my attempt...

You can find an explanation for Perl regular expressions on perlre.

<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
#Set the hostname, or maybe an empty string
#This is if you use 'absolute' url and not a 'relative' one
$hostname = "http://www.mysite.com";

#Catch url containing $hostname/subdir/Flash/file or $hostname/subdir/Flash/
<rule>
<from>$hostname([\/

Blaise
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2003

posted posted 12-08-2003 07:24

Hi there, thanks for everyones help so far, I really appreciate you taking the time for me and my problem.

Here's what I've got so far, and it works partly.

code:
<rule>
<condition name="host">www.mysite.com</condition>
<from>^/(.*)/(.*?)$</from>
<to>/$1/Flash/$2</to>
</rule>

<rule>
<condition name="host">www.mysite.com</condition>
<from>^/(.*)/Flash/(.*?)$</from>
<to type="redirect">/$1/Flash/Flash/$2</to>
</rule>

This checks that the right domain is used, and then makes the substitute, it also checks that in the case that the Flash folder ahs been entered into the address (eg. a link has been clicked) then it will remove the dupe and load normally.

This is real progress, but there's one more problem that I can't get my head round, unfortunatly there are a few pages that don't have a Flash or nonFlash folder for example the index page of the the entire site www.mysite.com.au/index.jsp. Can anyone help out here to create a rule that won't do it for this example?

TIA,

Blaise

« BackwardsOnwards »

Show Forum Drop Down Menu