.htaccess - 删除index.php并重定向到https子域

标签 .htaccess codeigniter subdomain

.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/

相关文章:

php - MySQL 返回所有带有空字符串的行作为 where 子句

javascript - AJAX POST 无法在 CODEIGNITER 中加载 div View

php - 所见即所得编辑器安全问题(防止恶意输入)

不同主机上的子域

.htaccess - 如何移除 .htaccess 病毒?

php - Prestashop 在数据库中更改旧域后重定向到旧域

.htaccess - X-Robots-Tag - Noindex .htaccess 中的几个文件

ruby-on-rails - 如何允许客户子域网站使用其自己的域

PHP:子域上的多语言网站,没有许多 public_html 副本

.htaccess - 如何将多个域 Root 到多个子文件夹