Forum

Redirecting a subset of old URIs to new ones, with a suffix

Ali
28 June 2012, 22:12
Hi,

I'm trying to set up a new VPS server with Hiawatha, which I'm planning migrate several sites currently hosted on different web hosts.

I found the UrlToolkit of Hiawatha pretty easy to setup, and managed to port the rules of the sites I want to migrate without much effort. However, I'm having a problem with creating a specific redirect rule.

What I'm trying to achieve is to add a suffix to a subset of URIs on one of the sites I'm migrating. What I want from Hiawatha is to first find the URIs that does not contain the suffix I want to add, then redirect those URIs to new ones with the added suffix (i.e. /tester/test-me to /tester/test-me-now)

I've tried these alternatives, without success;
Match ^/tester/([a-z0-9-]+(?!-now$)) Redirect http://www.example.com/tester/$1-now
Match ^/tester/([a-z0-9-]+(?<!-now$)) Redirect http://www.example.com/tester/$1-now


I know this is mostly a question about regex, rather than Hiawatha itself, but thought frequenters of this forum might have previous experience on the subject.

Thanks in advance.

Hiawatha version: 8.4
Operating System: Debian Wheezy
Hugo Leisink
28 June 2012, 23:57
I'm not a regex-expert, so I don't know the answer. What I do know is that it's best practice to use URL rewriting only for redirecting requests for non-existing files to a single index file (index.php). I think that you better put the things you try to do via URL rewriting in your application.
Ali
29 June 2012, 16:14
I agree with the idea rewrites being best practice about forwarding requests to the code, but they don't solve the problem with the existing links on the referrers (i.e. search engines, social media sites, blogs, etc.). I need 301 "permanently moved" redirects for external links, or they'll all die with 404s
Ali
6 July 2012, 21:03
As far as I understand from this serverfault post [serverfault.com], there are two types of regular expression support: PCRE and POSIX. According to the responder on that post, POSIX regular expressions does not support negative lookahead rules.

Before giving up on my redirect scheme, I'd like to ask another question; which kind of regular expressions does Hiawatha support? Or, in particular, does Hiawatha supports negative lookahaed [www.regular-expressions.info] rules?
Hugo Leisink
7 July 2012, 09:19
Hiawatha uses the default regex library under Unix, which is the POSIX type. Like I said, I'm no regex-expert, so I have no idea what negative lookahead is. When I have more time, I will look at the provided link.
Ali
7 July 2012, 11:24
OK, thanks for the answer Hugo.

By the way, it looks like I was wrong about there being two types of regular expression support According to the reference I've pointed out on my previous post, there are too many alternatives [www.regular-expressions.info] and even POSIX regular expressions has two different flavors (and lookarounds does not supported by both).

Please accept this [Perl Compatible Regular Expression Library (PCRE) support] as my new feature request for Hiawatha.
This topic has been closed.