Closed hexfusion closed 9 years ago
I'm using this table in one of my shops. Actually default for status code should be 301.
MariaDB [shop]> describe path_redirect
-> ;
+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| path_source | varchar(255) | NO | PRI | | |
| path_target | varchar(255) | NO | | | |
| status_code | int(11) | NO | | 0 | |
| last_used | int(11) | NO | | 0 | |
+-------------+--------------+------+-----+---------+-------+
4 rows in set (0.25 sec)
I am motivated to make this work if you think this makes sense I will write a few tests.
https://github.com/interchange/interchange6-schema/commit/724064c1a1e1e1f61c86321bfa69da75d160a018
possible use case
hook 'before' => sub {
my $tokens = shift;
my $redirect;
# path
my $path = request->path;
$path =~ s|^/||;
# check for redirects
$redirect = shop_schema->resultset('NavigationRedirect')->find({ uri => $path });
my $redirect_uri = $redirect->find_related('navigation', { navigation_id => $redirect->navigation_id })->uri if $redirect;
redirect '/' . $redirect_uri, $redirect->status_code if $redirect_uri;
};
Yes this could be a feature of Dancer::Plugin::Interchange6.
:+1:
@SysPete what do you think of the idea/classes ^^
I think a single class as per @racke's path_redirect is enough unless @sbatschelet can persuade me otherwise since atm I don't see the advantage of the extra db query plus extra code. Slotted in immediate before https://github.com/interchange/Dancer-Plugin-Interchange6/blob/master/lib/Dancer/Plugin/Interchange6/Routes.pm#L373 this is a simple and useful addition.
Closed now we have UriRediret class.
I have a use for a redirect process for Navigation and Product to manage SEO and discontinued products. I propose 2 new classes NavigationRedirect and ProductRedirect. This will allow uri -> $product/$navigation mapping. I think this would be a nice feature and easily managed without much code. I considered jamming this into Navigation but I think that the target of the redirect should be direct relationships to $product and $nav. Open to input on this.