要在 CyberPanel 中配置 301 重定向,可以按照以下步骤操作:
- 通过CyberPanel面板添加重定向
- 进入域名管理区域,使用“域名重定向”部分添加您想要转发/重定向的位置2。
- 使用重写规则
- .htaccess 文件
- 在附加域的文件夹中创建一个
.htaccess
文件,并包含以下代码以将.org
域重定向到.net
域4:
RewriteEngine on RewriteCond %{HTTP_HOST} ^yourdomain.org$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.yourdomain.org$ [NC] RewriteRule ^(.*)$ https://www.otherdomain.net/$1 [L,R=301,NC]
- 在CyberPanel中,OpenLiteSpeed可能无法读取您通过文件管理器创建的规则。您需要使用子域名启动器来保存子域的重写规则4。
- 在附加域的文件夹中创建一个
- 强制将所有请求从 HTTP 重定向到 HTTPS
- 通过添加以下重写规则,强制重定向所有URL以使用HTTPS5:
RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
请记住,在进行任何更改后,您可能需要重新启动 LiteSpeed4。
Citations:
- https://forum.openlitespeed.org/threads/please-help-with-301-redirects-in-htaccess-file.4558/
- https://community.cyberpanel.net/t/domain-redirect/43465
- https://community.cyberpanel.net/t/how-to-redirect-old-domain-full-content-to-a-new-domain/17528
- https://community.cyberpanel.net/t/how-can-i-set-up-an-addon-domain-and-redirect-to-the-main-domain/14594
- https://scriptstown.com/how-to-install-wordpress-on-cyberpanel-with-domain-and-ssl/
- https://community.cyberpanel.net/t/url-is-redirecting-to-old-domain-after-restoring-a-wordpress-backup-due-to-redis/32294
- https://community.cyberpanel.net/t/how-to-redirect-old-domain-full-content-to-a-new-domain/17528/3
- https://community.cyberpanel.net/t/tutorial-how-to-make-redirect-with-or-without-www-and-redirect-to-https/14058
- https://community.cyberpanel.net/t/the-preview-function-of-the-test-website-keep-redirecting-to-the-old-website-on-another-server/31104
- https://community.cyberpanel.net/t/need-help-with-redirecting-specific-url-to-a-different-url-on-main-domain/19955
- https://bobcares.com/blog/redirect-http-to-https-cyberpanel/
- https://rmalis.com/cyberpanel-redirect-domain-name-to-another-including-urls/
- https://community.cyberpanel.net/t/trouble-with-301-redirects-with-cyberpanel-ols/31397
- https://community.n8n.io/t/install-n8n-on-docker-in-cyberpanel/14029
- https://www.namecheap.com/support/knowledgebase/article.aspx/385/2237/how-to-set-up-a-url-redirect-for-a-domain/
- https://community.cyberpanel.net/t/301-redirect-not-working-cyberpanel-ols/35172
- https://natsav.com/blog/how-to-manage-multiple-websites-with-cyber-panel/
- https://www.inmotionhosting.com/support/website/setting-up-a-301-permanent-redirect-via-htaccess/
- https://www.hostinger.com/tutorials/how-to-redirect-a-domain
- https://tonyteaches.tech/cyberpanel-redirect-http-to-https/