fork / craft-here
使用SEO插件的重定向功能来编写nginx和apache重定向映射配置文件(非常适合无头Craft CMS设置)
2.0.1
2023-07-13 12:52 UTC
Requires
- craftcms/cms: ^4.0.0-alpha
- ether/seo: ^4.0.0
Requires (Dev)
- craftcms/rector: dev-main
This package is auto-updated.
Last update: 2024-09-13 15:44:40 UTC
README
目录
功能
- 直接在服务器配置中管理自定义重定向(适用于Nginx和Apache)
- 非常适合无头Craft CMS设置
- 使用Craft SEO插件的重定向功能和UI
要求
- Craft CMS 4
- Craft SEO插件
设置
1. 安装
安装包
cd /path/to/project
composer require fork/craft-here
2. 配置文件
- 将示例
config.php
复制到您的Craft配置目录,并将其重命名为redirects.php
- 指定服务器类型(如果您使用nginx,请指定重载命令)。以下是一个示例
<?php return [ // Global settings '*' => [ 'serverType' => 'nginx' // or 'apache' ], // Dev environment settings 'dev' => [ //'redirectsReloadCommand' => 'my-command', ], // Staging environment settings 'staging' => [ ], // Production environment settings 'production' => [ //'redirectsReloadCommand' => 'sudo /etc/init.d/nginx reload', ], ];
在您的服务器配置中包含重定向映射文件(这些文件将在插件安装后创建)
# NGINX EXAMPLE:
# see https://serverfault.com/a/890715/487169 for why we use "[.]" instead of a regular period "."
include /var/www/html/redirects/my.domain.com/redirects-301[.]map;
include /var/www/html/redirects/my.domain.com/redirects-302[.]map;
# 301 MOVED PERMANENTLY
if ($redirect_moved = false) {
set $redirect_moved "";
}
if ($redirect_moved != "") {
rewrite ^(.*)$ $redirect_moved permanent;
}
# 302 FOUND (aka MOVED TEMPORARILY)
if ($redirect_found = false) {
set $redirect_found "";
}
if ($redirect_found != "") {
rewrite ^(.*)$ $redirect_found redirect;
}
# APACHE EXAMPLE:
RewriteEngine On
RewriteMap redirects-301 txt:/var/www/html/redirects/my.domain.com/redirects-301.map
RewriteMap redirects-302 txt:/var/www/html/redirects/my.domain.com/redirects-302.map
RewriteCond ${redirects-301:%{REQUEST_URI}} ^.+$
RewriteRule .* https://${redirects-301:%{HTTP_HOST}%{REQUEST_URI}} [redirect=permanent,last]
RewriteCond ${redirects-302:%{REQUEST_URI}} ^.+$
RewriteRule .* https://${redirects-302:%{HTTP_HOST}%{REQUEST_URI}} [redirect=temp,last]
使用
插件安装后,将创建所有必要的重定向映射文件,需要包含到服务器配置中。之后只需使用SEO插件UI来管理您的重定向。
路线图
- 设置(而不是配置文件)可能