Mojolicious::Plugin::RedirectHost - Redirects requests from mirrors to the main host (useful for SEO)
Version 0.03
Generate 301 redirect from http://mirror.main.host/path?query to http://main.host/path?query
http://mirror.main.host/path?query
http://main.host/path?query
# Mojolicious $app->plugin('RedirectHost', host => 'main.host'); # Mojolicious::Lite plugin RedirectHost => { host => 'main.host' };
All requests with Host header not equal to the host option will be redirected to the main host
Host
host
Main domain. All requests to the mirrors will be redirected to the host (domain) This option is required. Without it plugin do nothing
code
$app->plugin('RedirectHost', host => 'main.host', code => 302);
Type of redirection. Default 301 (Moved Permanently)
url
All keys of the url hash (except query) become Mojo::URL object's methods, regarding old request
query
# 302: http://mirror.main.host/path?query -> http://main.host/path?query $app->plugin('RedirectHost', host => 'main.host', code => 302);
You can replace some parts of the old request, for example scheme (https), or add extra query parameters ?a=b to the end
https
?a=b
# http://mirror.main.host/foo -> https://main.host/foo?a=b $app->plugin( 'RedirectHost', host => 'main.host', url => { scheme => 'https', query => [{a => 'b'}] } );
How to use url->{query} option (pay attention to '[]')
# append ?a=old&foo=bar -> ?a=old&foo=bar&a=b url => {query => [{a => 'b'}] # merge ?a=old&foo=bar -> ?a=b&foo=bar url => {query => [[a => 'b']] # replace ?a=old&foo=bar -> ?a=b url => {query => [a => 'b']} # this works too url => {query => [Mojo::Parameters->new(a => 'b')]} # Wrong!!! Don't do this. Don't forget [] url => {query => Mojo::Parameters->new(a => 'b')}
See "query" in Mojo::URL
You can pass a string to the url part of options
# http://mirror.main.host/foo -> http://google.com $app->plugin( 'RedirectHost', host => 'main.host', url => 'http://google.com' );
New url as an Mojo::URL object
# http://mirror.main.host/foo -> http://google.com $app->plugin( 'RedirectHost', host => 'main.host', url => Mojo::URL->new('http://google.com') );
You can pass options to the plugin with the help of your config. Use redirect_host key.
redirect_host
$app->config(redirect_host => {host => 'main.host'});
Register. См "register" in Mojolicious::Plugin
Play around requests without "Host" header like this:
GET / HTTP/1.1
Alex, <alexbyk at cpan.org>
<alexbyk at cpan.org>
Please report any bugs or feature requests to bug-mojolicious-plugin-redirecthost at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mojolicious-Plugin-RedirectHost. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-mojolicious-plugin-redirecthost at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Mojolicious::Plugin::RedirectHost
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mojolicious-Plugin-RedirectHost
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Mojolicious-Plugin-RedirectHost
CPAN Ratings
http://cpanratings.perl.org/d/Mojolicious-Plugin-RedirectHost
Search CPAN
http://search.cpan.org/dist/Mojolicious-Plugin-RedirectHost/
Copyright 2012 Alex.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'См'. Assuming CP1252
To install Mojolicious::Plugin::RedirectHost, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::RedirectHost
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::RedirectHost
For more information on module installation, please visit the detailed CPAN module installation guide.