httpd match pattern issue

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

httpd match pattern issue

Thuban
Hello,
I need to redirect some URLS with httpd. As example :

        /test/?d=2018/05/02/13/14/50-some-title

Must be redirected to /2018/05/02/some-title

My problem is that "?" is never matched.

Here is the pattern I use :

        location match "^/test/%?d=(%d%d%d%d/%d%d/%d%d)/%d%d/%d%d/%d%d%-(%g+)$" {
                block return 301 "/%1/$2"
                }


Any advice?
After many tests, it seems that the only problem is the "?"

thanks.

--
    thuban

Reply | Threaded
Open this post in threaded view
|

Re: httpd match pattern issue

Justina Colmena
On Thu, 24 May 2018 16:47:46 +0200
Thuban <[hidden email]> wrote:

> Hello,
> I need to redirect some URLS with httpd. As example :
>
> /test/?d=2018/05/02/13/14/50-some-title
>
> Must be redirected to /2018/05/02/some-title
>
> My problem is that "?" is never matched.
>
> Here is the pattern I use :
>
> location match
> "^/test/%?d=(%d%d%d%d/%d%d/%d%d)/%d%d/%d%d/%d%d%-(%g+)$" { block
> return 301 "/%1/$2" }
>
>
> Any advice?
> After many tests, it seems that the only problem is the "?"
>
> thanks.
>

The portion of the URL from the "?" on is the "query string" -- I
wonder if that isn't broken off before the pattern matching occurs and
simply passed on verbatim to the new location

In PHP you could accomplish a quick and easy redirection by creating a
file /var/www/htdocs/test/index.php something like this:

===%<-----
<?php
if(array_key_exists('d', $_GET)) {
        header('Location: /' . urlencode($_GET['d']));
}
else {/* ... */}
===%<-----

I believe that the variable $_GET['d'] has already been parsed
from the query string and urldecoded.

Otherwise, I am looking more into relayd(8) to accomplish redirections
and other header manipulation.