【发布时间】:2025-11-25 02:45:02
【问题描述】:
我需要在我们的 apache2 和站点 .htaccess 上(希望)设置高级(对我而言)重定向。 我们希望任何指向 www.example.com 和 example.com 或 https://www.example.com 的人都将被重定向到 https://example.com
问题是域后的链接必须有效。 例如,http://example.com/category/article/newest 和 https://www.example.com/category/article/newest 将在重定向后工作并指向正确的 https://example.com/category/article/newest
我们尝试了重定向,如您在附加的 .htaccess 中所见,但问题是它例如将 http://www.example.com/category/article/newest 重定向到 https://example.com/
我们当前的 .htaccess
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.$ [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule .* public/index.php
SetEnv APPLICATION_ENV development
<IfModule mod_php.c>
php_flag magic_quotes_gpc off
php_flag register_globals off
</IfModule>
【问题讨论】: