【问题标题】:Remove index.php and redirect to https sudomain删除 index.php 并重定向到 https 子域
【发布时间】:2018-10-03 02:33:21
【问题描述】:

.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

注意:需要上述.htaccess代码的组合版本。

【问题讨论】:

  • url 无法到达错误。我知道当我使用第二个 .htaccess 代码时的问题是我没有从 url 中删除 index.php 这意味着如果我到达 https://test.xyz.com/index.php/user/list 它会正常工作
  • 第一个是我最初使用的唯一代码。也就是去掉index.php。之后我评论了所有这些代码并尝试了第二个。
  • 当然是的..
  • 但是http://test.xyz.com/user/list 不起作用。即如果我们删除https
  • 是的,只有第一个块规则 https://test.xyz.com/user/list url 有效。

标签: .htaccess codeigniter subdomain


【解决方案1】:

您可以在站点根目录 .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]

清除浏览器缓存后测试或在新浏览器中测试。

【讨论】:

  • 完美!!。工作正常。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2019-04-02
  • 2012-06-03
  • 2016-03-11
  • 1970-01-01
  • 2016-03-15
  • 1970-01-01
  • 2020-05-26
  • 2015-03-21
相关资源
最近更新 更多