.htaccess 文件:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Options -Indexes
我想从 URL 中删除 index.php
,并且当有人在地址栏中输入 test.xyz.com
时,它应该重定向到 https:///test.xyz.com
.
我通过注释上面的代码尝试了如下一些代码,然后问题是当我输入 test.xyz.com
时,它会自动重定向到 https://test.xyz。 com
但当我转到其他链接(例如 https://test.xyz.com/user/list
)时,它显示错误。
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
因此,我需要一个更好的 .htaccess 文件,它将删除 index.php
并重定向到子域中所有 URL 的 https
。
NOTE: Need combined version of both the above
.htaccess
code.
最佳答案
您可以在站点根目录 .htaccess 中使用此代码:
DirectoryIndex index.php
Options -Indexes
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [L]
清除浏览器缓存后进行测试或在新浏览器中测试。
关于.htaccess - 删除index.php并重定向到https子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49974430/