Mod_Rewrite 对除一个文件之外的所有文件强制使用 HTTP

发布于 2024-07-29 06:43:35 字数 634 浏览 2 评论 0原文

抱歉,如果之前有人问过这个问题,但我找不到。 我有一个文件夹,当我访问该文件夹时,它会同时以 HTTPS 和 HTTP 方式加载。

我希望该文件夹中除一个文件之外的所有文件都以 HTTP 方式加载。 我在 HTTPS 中需要的文件是:login.php,该文件夹称为“forum”。 另外,如果有帮助的话:文件夹中的所有文件都是 *.php。

我正在尝试以下内容:

#RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^/login.php$ - [L]

#RewriteCond %{SERVER_PORT} ^443$
#RewriteRule ^(/login.php) $ https://%{HTTP_HOST}/$1 [QSA,NC,R,L]

#RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [QSA,NC,R,L]

当谈到 mod_rewrite 时,我有点业余,所以如果上面的内容完全关闭,请原谅我。 另外,如果您发布一个解决方案,如果您发布它并附上解释,我将不胜感激,这样我就可以真正了解它是如何工作的。

提前致谢! 大卫

Sorry if this has been asked before, but I couldn't find it.
I have a folder which when I visit loads in both HTTPS and HTTP.

I want all the files in that folder to load in HTTP except for one file.
The file I need in in HTTPS is: login.php and this folder is called "forum".
Also if it helps: All the files in the folder are *.php.

I was trying something along the lines of:

#RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^/login.php$ - [L]

#RewriteCond %{SERVER_PORT} ^443$
#RewriteRule ^(/login.php) $ https://%{HTTP_HOST}/$1 [QSA,NC,R,L]

#RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [QSA,NC,R,L]

I'm a bit of an amateur when it comes to mod_rewrite so forgive me if the above is completely off.
Also if you post a solution I would appreciate it if you post it with an explanation so I can actually LEARN how it works.

Thanks in advance!
David

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

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

发布评论

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

评论(2

灯下孤影 2024-08-05 06:43:35

尝试一下:

 Options +FollowSymLinks
 RewriteEngine On


 # port 443 traffic to http://, except login.php
 RewriteCond %{SERVER_PORT} ^443$
 RewriteCond %{REQUEST_URI} !^/login\.php$ [NC]
 RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

 # port 80 traffic for login.php to https://
 RewriteCond %{SERVER_PORT} ^80$
 RewriteCond %{REQUEST_URI} ^/login\.php$ [NC]
 RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Give this a try:

 Options +FollowSymLinks
 RewriteEngine On


 # port 443 traffic to http://, except login.php
 RewriteCond %{SERVER_PORT} ^443$
 RewriteCond %{REQUEST_URI} !^/login\.php$ [NC]
 RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

 # port 80 traffic for login.php to https://
 RewriteCond %{SERVER_PORT} ^80$
 RewriteCond %{REQUEST_URI} ^/login\.php$ [NC]
 RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
铁憨憨 2024-08-05 06:43:35

尝试这些规则:

RewriteCond %{SERVER_PORT} !=443
RewriteRule ^login\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{SERVER_PORT} !=80
RewriteRule !^login\.php$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Try these rules:

RewriteCond %{SERVER_PORT} !=443
RewriteRule ^login\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{SERVER_PORT} !=80
RewriteRule !^login\.php$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文