如果 REQUEST_URI 是特定目录,如何跳过 RewriteRule。这是一个 CodeIgniter 项目

发布于 2024-12-11 20:22:44 字数 1872 浏览 0 评论 0 原文

我有一个在 CentOS 上运行的 CodeIgniter 项目,并成功安装了 EV 证书。

我不希望在访问 /rss 目录时使用 SSL。我有这个工作,但我在升级过程中以某种方式破坏了它。

这是我的 .htaccess 文件,我认为它是正确的:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # redirect to SSL connection
    RewriteCond %{REQUEST_URI} !^/rss/
    RewriteCond %{SERVER_PORT} 80
#   R=301 sends HTTP Moved Permanently L=Last rule for this request
    RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]


    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

转到该网站,网址正确更改为 https://www .site.com 但访问 www.site.com/rss 也会更改为 https。 我不希望它对该目录使用 ssl。 我认为 .htaccess 文件是正确的,所以也许它是 CodeIgniter 的东西...... 如果有人有想法,我将非常感激。

I have a CodeIgniter project running on CentOS, with an EV cert successfully installed.

I don't want SSL used when the /rss directory is accessed. I had this working, but I broke it somehow during an upgrade.

Here is my .htaccess file, which I think is correct:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # redirect to SSL connection
    RewriteCond %{REQUEST_URI} !^/rss/
    RewriteCond %{SERVER_PORT} 80
#   R=301 sends HTTP Moved Permanently L=Last rule for this request
    RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]


    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

Going to the site, the url is correctly changed to https://www.site.com
But going to www.site.com/rss also gets changed to https.
I don't want it to use ssl for that directory.
I think the .htaccess file is correct, so maybe it is a CodeIgniter thing...
IF anyone has an idea, I would be very grateful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谎言 2024-12-18 20:22:44

可能发生的情况是 mod_dir 没有按照之前的顺序进行干预(如果您访问目录但不包含尾部斜杠,则默认情况下 mod_dir 将重定向到相同的 URL 尾部斜杠)。如果您尝试访问 http://www.site.com/rss RewriteCond %{REQUEST_URI } !^/rss/ 匹配(因为请求 uri 以 "/rss" != "/rss/" 开头),并且它被重写为 https://www.site.com/rss。然后 mod_dir 接管并将您重定向到“https://www.site.com/rss/”。有可能在升级之前,mod_dir 首先应用了重定向,因此您被重定向到“http://www.site.com/rss/”,然后第一个条件 (!^/rss/) 失败,因此您不会得到重写为 https://

尝试将第一个重写条件更改为:

RewriteCond %{REQUEST_URI} !^/rss/?$

因此 URI 像“/rss”“/rss/”将匹配失败并且不会重定向到 https://

What might be happening is that a mod_dir is not intervening in the order that it did before (mod_dir by default will redirect, if you access a directory but don't include a trailing slash, to the same URL with the trailing slash). If you try to access http://www.site.com/rss RewriteCond %{REQUEST_URI} !^/rss/ matches (since the request uri starts with "/rss" != "/rss/") and it gets rewritten to https://www.site.com/rss. Then mod_dir takes over and redirects you to "https://www.site.com/rss/". It's possible that before the upgrade, mod_dir applied the redirect first so you get redirected to "http://www.site.com/rss/" then the first condition (!^/rss/) fails, thus you don't get rewritten to https://

Try changing the first rewrite condition to:

RewriteCond %{REQUEST_URI} !^/rss/?$

So URI's like "/rss" and "/rss/" will fail the match and not get redirected to https://

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文