.htaccess - 使用 SSL 将 www 转换为非 www,无需 index.php

标签 .htaccess url-rewriting no-www

当我尝试从 url www.mypage.com 进入我的网站时,我得到类似 http://www.mypage.com/index.php/https://mypage.com/https://www.mypage.com 的信息....

当我从 url mypage.com 输入时,我得到 https://mypage.com - 还可以

当我从 url mypage.com/stuff 输入时,我得到 https://mypage.com/index.php/stuff (页面正在运行)

当我从 url www.mypage.com/stuff 输入时,我得到 https://mypage.com/index.php/stuff

我应该做什么?我希望始终有像 https://mypage.com 这样的网址没有index.php并且没有'www'。

我的.htaccess:

AddHandler application/x-httpd-php70 php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

谢谢!

最佳答案

尝试切换顺序,以便最后执行内部重定向到index.php/$1:

AddHandler application/x-httpd-php70 php
RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

关于.htaccess - 使用 SSL 将 www 转换为非 www,无需 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35162057/

相关文章:

.htaccess 转换文件夹中的 url 参数

JavaScript url 重写器

.htaccess - 在 Prestashop 的每个页面上启用 SSL

http - 仅将一个文件夹重定向到 HTTPS,将所有其他文件夹重定向到 HTTP

php - 如何将所有子目录页面重定向到父目录?

apache将一个目录下的所有hash标签重写为斜杠标签

wordpress - .htaccess 在 Wordpress 中用于 https 和 www 到非 www

perl 催化剂 www 到非 www 重定向

apache - WWW 到 NON WWW Urls(删除 WWW)使用 Apache (.htaccess)

.htaccess - htaccess 不起作用 - 简单的重写规则在我的网站上没有执行任何操作