如果 REQUEST_URI 是特定目录,如何跳过 RewriteRule。这是一个 CodeIgniter 项目
我有一个在 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 的东西...... 如果有人有想法,我将非常感激。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能发生的情况是 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://尝试将第一个重写条件更改为:
因此 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:
So URI's like "/rss" and "/rss/" will fail the match and not get redirected to https://