origammi/redirect-manager-bundle

用户可以通过网页图形界面指定重定向。

安装: 305

依赖: 0

建议者: 0

安全: 0

星标: 6

关注者: 19

分支: 8

类型:symfony-bundle

3.5.1 2023-07-24 05:40 UTC

This package is auto-updated.

Last update: 2024-09-24 08:07:47 UTC


README

Build Status Latest Stable Version Total Downloads SensioLabsInsight

安装

步骤 1: 添加到 composer.json

"require" :  {
    // ...
    "astina/redirect-manager-bundle":"dev-master",
}

步骤 2: 启用包

在内核中启用包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Astina\Bundle\RedirectManagerBundle\AstinaRedirectManagerBundle(),
    );
}

步骤 3: 导入路由文件

导入包的路由文件。根据需要更改前缀属性。

在 YAML 中

# app/config/routing.yml
astina_redirect_manager:
    resource: "@AstinaRedirectManagerBundle/Resources/config/routing.yml"
    prefix:   /redirect/

步骤 4: 翻译

如果您希望使用此包中提供的默认文本,请确保您在配置中启用了翻译器。

# app/config/config.yml

framework:
    translator: ~

步骤 5: 配置选项

在具有多个实体管理器的应用程序中,请配置新的管理器或确保默认管理器可以访问模式。

# app/config/config.yml
astina_redirect_manager:
    storage:
      entity_manager: redirect # Optional entity manager name, if ommitted default entity manager is used
    base_layout: "SomeBundle:SomeDir:index.html.twig"    # Override default Astina layout
    enable_listeners: false # Set to false to disable redirect listeners. Useful for service oriented architectures. Defaults to true

步骤 6: 更新您的数据库模式

$ php app/console doctrine:schema:update --force

用法

使用命令导入 URL

包知道如何导入用于重定向的 URL 的 CSV 文件。CSV 必须包含两列,其中第一列包含 urlFrom,第二列包含 urlTo。

$ php app/console armb:import /path/to/csv/file.csv [--redirect-code=302] [--count-redirects]

使用子域监听器进行重定向

如果监听器检测到使用了子域,则将访客重定向到具有名称 route_nameroute_params 和重定向代码 redirect_code 的 URL。

# app/config/config.yml

astina_redirect_manager:
    redirect_subdomains:
        route_name:           ~ # Required
        route_params:
            param1: some-value
            param2: some-different-value
        redirect_code:        301

警告

您必须在 parameters.yml 文件中设置参数 router.request_context.host。否则将使用 localhost 作为域名。

# app/config/parameters.yml

# ...
router.request_context.host: example.com
# ...