使用htaccess对子目录进行https重定向不适用于内部URL

时间:2016-10-19 10:42:14

标签: php .htaccess codeigniter

我正在尝试将子目录从http重定向到https。我使用codeigniter作为框架:

http(s)://www.abc.com/new/

这是我的htaccess看起来像这样

RewriteEngine On
RewriteBase /new/

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

RewriteCond %{REQUEST_URI}  !(\.png|\.pdf|\.jpg|\.gif|\.jpeg|\.bmp|\.js|\.css|\.html|\.php|\.txt|\.ttf|\.svg|\.woff|\.woff2)$
RewriteCond %{REQUEST_URI}  !js_elements
RewriteRule ^(.*)$ index.php?/$1 [L]

现在,当我使用

访问我的网站时
abc.com/new 

然后它重定向到我

http(s)://www.abc.com 

这很好但是当我直接点击任何内部网址时

abc.com/new/customer/customer_list

那么它不会将我重定向到http(s) 任何人都可以解决我的问题吗?

1 个答案:

答案 0 :(得分:0)

Current folder layout
-index.php
-/xyz
    -index.php

your requirement is to turn this url
http://example.com/xyz/?username=xyz
into this url
http://example.com/xyz1/xyz


-----
use this code inside /xyz/.htaccess:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /xyz/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?xyz=$1 [L,QSA]
相关问题