Can someone help with a simple rule?

9 views
Skip to first unread message

Daniel

unread,
Nov 21, 2009, 1:55:52 AM11/21/09
to UrlRewrite

I currently have this rule on my site which works great:

<rule>
<from>^/(.+)/$</from>
<to>/index.cfm?/$1</to>
</rule>

So if someone writes in a URL such as:

http://www.mysite.com/something/more/

It will redirect to

http://www.mysite.com/index.cfm?something/more/

Which is all good.

----

My issue is I also want it to redirect if it doesn't have a trailing
slash so that:

http://www.mysite.com/something/more

wll get redirected a above. The issue is the word 'more' needs to be
checked if it contains a . as I don't want it redirecting a filename.
I know this is easy for anyone with rewriting experience (which I
unfortunately don't have).

Thanks in advance,
Daniel





kayak...@gmail.com

unread,
Nov 21, 2009, 4:33:16 PM11/21/09
to urlre...@googlegroups.com
If I understand what you want it seems like:

<rule>
<from>^/(.+/more)/?$</from>
<to>/index.cfm?/$1</to>
</rule>

This assumes that "more" should be at the end. Your original rule accepted anything including "more". If you need to accept anything where "more" appears in the above <from> then change the "more" to ([^.]+)

Hope that helps. A book on Perl regular expressions would help you in devising your patterns.

Andy.
Sent from my Verizon Wireless BlackBerry

Daniel

unread,
Nov 21, 2009, 11:40:05 PM11/21/09
to UrlRewrite
Thanks for your help.

I actually want to check if the last part contains a dot which would
make it a file and then not redirect.

http://www.mysite.com/something/more/whatever/ (should redirect)
http://www.mysite.com/something/more/whatever (should redirect)
http://www.mysite.com/something/more/whatever.gif (should NOT
redirect)

Or I guess the other way to do this is to run a fule first to add a
slash on the end (if there is no dot)..

http://www.mysite.com/something/more/whatever/ (Doesn't redirect)
http://www.mysite.com/something/more/whatever (redirects to
http://www.mysite.com/something/more/whatever/)
http://www.mysite.com/something/more/whatever.gif (Doesn't redirect)

Then I can run the rule on it that I already have above.

The site I am working on has thousands of 'paths' so I don't want to
code them all in to the redirect.
I just need it to redirect and path that doesn't have a filename on
the end.

Thanks
> Daniel- Hide quoted text -
>
> - Show quoted text -

Wim De Smet

unread,
Nov 22, 2009, 10:07:33 AM11/22/09
to urlre...@googlegroups.com
Hi,

On Sun, Nov 22, 2009 at 5:40 AM, Daniel <dan...@timespace.com.au> wrote:
> I actually want to check if the last part contains a dot which would
> make it a file and then not redirect.
>
> http://www.mysite.com/something/more/whatever/   (should redirect)
> http://www.mysite.com/something/more/whatever   (should redirect)
> http://www.mysite.com/something/more/whatever.gif (should NOT
> redirect)

> [...]


> The site I am working on has thousands of 'paths' so I don't want to
> code them all in to the redirect.
> I just need it to redirect and path that doesn't have a filename on
> the end.

How about:
<from>^(.*/[^./]*)$</from>

This will match:
- anything ending in a slash (.*/)
- anything ending in a slash with a trailing section that doesn't
contain dots or slashes [^./]
- will unfortunately also redirect if you have something like
/blah/dot.gif/ because of the trailing slash

I'm not entirely sure whether it's correct on sunday afternoon but it
looks sorta good to me. Might do a bit too much backtracking there but
that's hardly ever a problem.

regards,
Wim

Daniel

unread,
Nov 23, 2009, 5:36:34 AM11/23/09
to UrlRewrite
I just had to add a slash at the beginning so it looks like:

<from>^/(.+).htm$</from>

And then it worked so it was very close. I don't why this fixed it -
just similar to what was there before - as I don't really know what
I'm doing with this stuff, anyway all good now.

Thanks again for your help on this,

Daniel

On Nov 23, 2:07 am, Wim De Smet <krom...@gmail.com> wrote:
> Hi,
>
> On Sun, Nov 22, 2009 at 5:40 AM, Daniel <dan...@timespace.com.au> wrote:
> > I actually want to check if the last part contains a dot which would
> > make it a file and then not redirect.
>
> >http://www.mysite.com/something/more/whatever/  (should redirect)
> >http://www.mysite.com/something/more/whatever  (should redirect)
> >http://www.mysite.com/something/more/whatever.gif(should NOT
Reply all
Reply to author
Forward
0 new messages