terminal42 / contao-url-rewrite
Contao开源内容管理系统(CMS)的URL重写工具包
1.7.5
2023-09-22 07:43 UTC
Requires
- php: ^7.2 || ^8.0
- bacon/bacon-qr-code: ^2.0
- contao/core-bundle: ^4.13 || ^5.0
- doctrine/dbal: ^2.11 || ^3
- symfony/config: ^5.0 || ^6.0
- symfony/dependency-injection: ^5.0 || ^6.0
- symfony/expression-language: ^5.0 || ^6.0
- symfony/filesystem: ^5.0 || ^6.0
- symfony/http-foundation: ^5.0 || ^6.0
- symfony/http-kernel: ^5.0 || ^6.0
- symfony/routing: ^5.0 || ^6.0
Requires (Dev)
- contao/calendar-bundle: ^4.4
- contao/faq-bundle: ^4.4
- contao/manager-plugin: ^2.0
- contao/news-bundle: ^4.4
- contao/test-case: ^4.0
- symfony-cmf/routing: ^2.1
Conflicts
- contao/manager-plugin: <2.0 || >=3.0
README
该扩展为Contao提供了一种新的设置各种URL重写的方法。可用的配置提供者是
- 包配置提供者 - 条目来自
config.yml
文件 - 数据库提供者 - 条目来自后端模块
幕后,规则被添加为内部应用程序路由器中的路由,这允许使用Symfony路由组件提供的所有功能。
安装
通过Composer安装包
composer require terminal42/contao-url-rewrite
短URL迁移
由于扩展 fritzmg/contao-short-urls 已被弃用,您可以使用扩展 bwein-net/contao-migrate-short-urls 将短URL迁移到URL重写。
配置
包配置
包配置是可选的。在这里,您可以定义条目并禁用后端管理模块。
注意:如果您想使用 %
字符,请确保它已通过重复它 %%
正确转义。
# 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}}'
在非Contao管理版下运行
如果您正在运行Contao管理版,则该扩展应该直接可用。对于所有其他系统,您还必须在配置文件中注册路由配置。
# config/routing.yml imports: - { resource: '@Terminal42UrlRewriteBundle/Resources/config/routing.yml' }
示例
- 在谷歌地图上查找地址
Type: basic
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
- 重定向到特定的新闻条目
Type: basic
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
- 带有查询字符串的重写旧URL
Type: expert
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
- 重写包含斜杠(没有查询字符串)的URL到新域名
Type: basic
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
创建自定义配置提供者
除了现有的提供者之外,您还可以创建自己的类,该类提供重写配置。新服务必须实现 Terminal42\UrlRewriteBundle\ConfigProvider\ConfigProviderInterface 接口,并使用适当的标签进行注册。
services: app.my_rewrite_provider: class: AppBundle\RewriteProvider\MyRewriteProvider public: false tags: - { name: terminal42_url_rewrite.provider, priority: 128 }