NAME
Mojolicious::Plugin::RedirectHost::RuTutorial - Russian tutorial
VERSION
Version 0.03_2
SYNOPSIS
Сделать 301 редирект с 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' };
Теперь любые запросы, приходящие на зеркало (тобишь если заголовок запроса "Host" не совпадает с параметром "host", переданном плагину), будут переадресовываться на основной "host", по умолчанию со статусом 301. Например, для того, чтобы Яндекс-Шмандекс и Гугл-Шмугл не разбавляли показатели сайта по поддоменам
OPTIONS/USAGE
host
Основной домен. Запросы, заголовок Host
в которых не совпадает с доменом, будут переадресованы на основной домен Это обязательный параметр, без него плагин матерится как Джигурда и ничего не делает
code
$app->plugin('RedirectHost', host => 'main.host', code => 302);
Код ответа, по умолчанию 301 (Moved Permanently)
url
Все ключи в хеше url
(кроме query
) становятся методами объекта Mojo::URL, те, которые не затираются - берутся с текущего запроса
# 302: http://mirror.main.host/path?query -> http://main.host/path?query
$app->plugin('RedirectHost', host => 'main.host', code => 302);
Можно изменить параметры запроса, заменив значения текущего запроса или добавив новые. Например, изменить протокол на 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'}] }
);
Значение url->{query} можно использовать так (обрати внимание на []):
# 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')}
Подробнее смотри "query" in Mojo::URL
Полность указать новый запрос можно строкой
# http://mirror.main.host/foo -> http://google.com
$app->plugin(
'RedirectHost',
host => 'main.host',
url => 'http://google.com'
);
Указать новый запрос объектом Mojo::URL
# http://mirror.main.host/foo -> http://google.com
$app->plugin(
'RedirectHost',
host => 'main.host',
url => Mojo::URL->new('http://google.com')
);
CONFIG
Необходимые настройки можно указать в конфиге приложения по ключу redirect_host
$app->config(redirect_host => {host => 'main.host'});
METHODS
register
Регистрирует плагин. См L<Mojolicious::Plugin/register>
TODO
Play around requests without "Host" header like this:
GET / HTTP/1.1
AUTHOR
Alex, <alexbyk at cpan.org>
BUGS
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.
SUPPORT
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
CPAN Ratings
http://cpanratings.perl.org/d/Mojolicious-Plugin-RedirectHost
Search CPAN
http://search.cpan.org/dist/Mojolicious-Plugin-RedirectHost/
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
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:
- Around line 13:
Non-ASCII character seen before =encoding in 'Сделать'. Assuming UTF-8