【问题标题】:https redirect of subdirectory using htaccess does not work for inner url使用 htaccess 的子目录的 https 重定向不适用于内部 url
【发布时间】:2016-10-19 10:42:13
【问题描述】:

我正在尝试将子目录从 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) 谁能解决我的问题?

【问题讨论】:

  • RewriteCond %{QUERY_STRING} !^/new 在里面做什么?
  • @arkascha 我应该删除这个吗?
  • 我不知道。我问为什么。只有你能回答。
  • @arkascha 我也不知道。我只是在谷歌上搜索,发现了这个,我尝试了一下,但不管有没有,它都不起作用。
  • 听起来您甚至从未费心阅读您使用的工具的文档。从来没有真正尝试过了解您尝试的事情是如何工作的,而是只是尝试一下?这很少是一个好主意。开始做你的功课吧,因为到目前为止,试验和猜测的方法显然没有成功,是吗? httpd.apache.org/docs/current/mod/mod_rewrite.html 在那里你会发现RewriteConds 使用%{QUERY_STRING} 实际做什么的解释。

标签: php .htaccess codeigniter


【解决方案1】:
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]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-23
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多