【发布时间】:2021-04-21 19:17:05
【问题描述】:
美好的一天!我想使用 .htaccess 文件实现 3 个任务:
- 仅适用于
https协议 - 创建从
https://www.example.com到https://example.com的 301 重定向 - 将所有请求重定向到
index.php文件
我最好的 .htaccess 版本如下所示,但我不确定这是否是正确的决定:
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} .* [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php
如有任何建议,我将不胜感激!
【问题讨论】:
标签: apache .htaccess mod-rewrite https url-rewriting