当我尝试从 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/