定制 terminal42/contao-url-rewrite 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

terminal42/contao-url-rewrite

Composer 安装命令:

composer require terminal42/contao-url-rewrite

包简介

URL Rewrite bundle for Contao Open Source CMS

README 文档

README

The extension provides a new way for Contao to set various URL rewrites. The available config providers are:

  • Bundle config provider – the entries are taken from config.yml file
  • Database provider – the entries are taken from backend module

Behind the scenes, the rules are added as routes to the internal application router which allows to use all the features provided by the Symfony Routing component.

Installation

Install the bundle via Composer:

composer require terminal42/contao-url-rewrite

Migration of short URLs

Since the extension fritzmg/contao-short-urls has been abandoned, you can migrate short URLs to URL rewrites with the extension bwein-net/contao-migrate-short-urls.

Configuration

Bundle configuration

The bundle configuration is optional. Here you can define the entries and disable the backend management module.

Note: if you want to use the % character, make sure it is properly escaped by doubling it %%.

# config/config.yml
terminal42_url_rewrite:
    backend_management: false # Disable backend management of entries (true by default)
    entries: # Optional entries
        -
            request: { path: 'find/{address}' }
            response: { code: 303, uri: 'https://www.google.com/maps?q={address}' }

        -
            request:
                path: 'news/{news}'
                requirements: {news: '\d+'}
            response:
                code: 301
                uri: '{{news_url::{news}|absolute}}'

        -
            request:
                path: 'home.php'
                hosts: ['localhost']
                condition: "context.getMethod() == 'GET' and request.query.has('page')"
            response:
                uri: '{{link_url::{page}|absolute}}'

Running under non Contao managed edition

If you are running the Contao Managed Edition then the extension should work out of the box. For all the other systems you have to additionally register the routing configuration in the config files:

# config/routing.yml
imports:
  - { resource: '@Terminal42UrlRewriteBundle/Resources/config/routing.yml' }

Examples

  1. Find address on Google Maps:
Path restriction: find/{address}
Response code: 303 See Other
Response URI: https://www.google.com/maps?q={address}
---
Result: domain.tld/find/Switzerland → https://www.google.com/maps?q=Switzerland
  1. Redirect to a specific news entry:
Path restriction: news/{news}
Requirements: [news => \d+]
Response code: 301 Moved Permanently
Response URI: {{news_url::{news}|absolute}}
---
Result: domain.tld/news/123 → domain.tld/news-reader/foobar-123.html
Result: domain.tld/news/foobar → 404 Page Not Found
  1. Rewrite legacy URLs with query string:
Path restriction: home.php
Request condition: context.getMethod() == 'GET' and request.query.has('page')
Response code: 301 Moved Permanently
Response URI: {{link_url::{page}|absolute}}
---
Result: domain.tld/home.php?page=123 → domain.tld/foobar-123.html
  1. Rewrite URLs including slashes (without query string) to new domain:
Hosts restriction: [domain.com]
Path restriction: /{wildcard}
Requirements: [wildcard => .*]
Response code: 301 Moved Permanently
Response redirect URL: https://domain.tld/{wildcard}
---
Result: domain.com/blog/test → https://domain.tld/blog/test

Create a custom config provider

In addition to the existing providers you can create your own class that provides the rewrite configurations. The new service must implement the Terminal42\UrlRewriteBundle\ConfigProvider\ConfigProviderInterface interface and be registered with the appropriate tag:

services:
    app.my_rewrite_provider:
        class: AppBundle\RewriteProvider\MyRewriteProvider
        public: false
        tags:
            - { name: terminal42_url_rewrite.provider, priority: 128 }

Resources

  1. Symfony Routing
  2. Symfony Routing Component
  3. How to Restrict Route Matching through Conditions
  4. How to Define Route Requirements

terminal42/contao-url-rewrite 适用场景与选型建议

terminal42/contao-url-rewrite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 102.15k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2017 年 09 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「url」 「redirect」 「rewrite」 「contao」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 terminal42/contao-url-rewrite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 terminal42/contao-url-rewrite 我们能提供哪些服务?
定制开发 / 二次开发

基于 terminal42/contao-url-rewrite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 102.15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 16
  • 点击次数: 19
  • 依赖项目数: 3
  • 推荐数: 1

GitHub 信息

  • Stars: 15
  • Watchers: 5
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-18