删除整个站点的 www,在某些目录上强制使用 https,在其余目录上强制使用 http?

发布于 2024-10-03 05:37:51 字数 1767 浏览 5 评论 0原文

首先,我想删除www。来自我的域名

http://www.example.com =>; http://example.com

我还希望某些目录是安全的 (https),​​而其余目录仍然是 http

< a href="http://example.com/login" rel="noreferrer">http://example.com/login => https://example.com/login

显然它需要适用于所有条件,例如,如果有人输入:

http://www.example.com/login =>; https://example.com/login

此外,当人们离开登录页面时,它会返回到 http。目前在 .htaccess 中,以下内容是由我正在使用的软件自动完成的,我想它需要在那里才能工作:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php

关于如何实现梦想控制所有这些事情有什么想法吗?

提前致谢!

===================

@Gumbo 按照您的建议,这是我完整的 .htaccess

RewriteEngine On


# remove www from host
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]

# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(login)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(login)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php


Options -Indexes

导航到 http://example/login 仍然会转到 http://example/index.php 时它应该转到 https://example/login 我的顺序错误吗?

Firstly, I would like to remove the www. from my domain name

http://www.example.com => http://example.com

I would also like for certain directories to be secure (https), while the rest remain http

http://example.com/login => https://example.com/login

Obviously it needs to work for all conditions, for example if someone types in:

http://www.example.com/login => https://example.com/login

Also when people navigate away from the login page it returns to http. Currently in the .htaccess is the following which is done automatically by the software I am using and I suppose needs to be there for it to work:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php

Any ideas on how I can achieve dream control all these things?

Thanks in advance!

===================

@Gumbo Following your advice this is my complete .htaccess

RewriteEngine On


# remove www from host
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]

# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(login)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(login)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php


Options -Indexes

Navigating to http://example/login still goes to http://example/index.php when it should go to https://example/login Do I have the order wrong?

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

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

发布评论

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

评论(4

盛夏已如深秋| 2024-10-10 05:37:51

尝试这些规则:

# remove www from host
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]

# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(login|foo|bar|…)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(login|foo|bar|…)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

您可能还需要添加一些附加条件,以便仅更改 GET 和 HEAD 请求上的协议,而不更改 POST 请求上的协议。

Try these rules:

# remove www from host
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]

# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(login|foo|bar|…)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(login|foo|bar|…)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

You also might want to add some additional conditions to only change the protocol on GET and HEAD requests but not on POST requests.

妥活 2024-10-10 05:37:51

这段代码对我有用:

<IfModule mod_rewrite.c>

   RewriteEngine on

   RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
   RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

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

</IfModule>

This code works for me:

<IfModule mod_rewrite.c>

   RewriteEngine on

   RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
   RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

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

</IfModule>
失而复得 2024-10-10 05:37:51

删除 www(已测试):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]

重定向(未测试):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \/login/?.*\ HTTP [NC]
RewriteRule ^(.*)$ https://yoursite.com/login [L,R=301]

remove www (tested):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]

redirect (not tested):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \/login/?.*\ HTTP [NC]
RewriteRule ^(.*)$ https://yoursite.com/login [L,R=301]
流年已逝 2024-10-10 05:37:51

阅读完所有帖子时间线后,我成功解决了以下错误:我的网站(c4dprime.com)已附加 https:在 mozilla firefox 浏览器中。 Google 和 internet explore 将域名地址显示为 http: (firefox 中的真正问题) 我不希望在任何浏览器中使用 https: 作为我的域名,因为在安装以下内容后,我的域名通过 https: 附加了一个未知的重定向 (导致此错误) WordPress 中的插件,(ssl 的轻松重定向)....我已经告诉每个人不要使用任何低级别的 WordPress 插件。

反正!通过谷歌搜索引擎阅读了有关该主题的许多文章和教程后。现在我很高兴地说我已经通过这篇文章的提示解决了这个问题。请记住关于我的一件事,我对这种形式和 WordPress 很陌生。

这个技巧对我很有帮助,

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]

在编辑或对我的 .htaccess 文件进行一些更改后,我现在使用的代码解决了这个错误。

AddHandler c4d-prime .com

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteBase /
RewriteRule ^$ http://www.c4dprime.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

After reading this all post time line i have get success for following error: My website(c4dprime.com) was attached https: in mozilla firefox browser. Google and internet explore are show domain address as http: (The real problem in firefox) I did not want https: for my domain in any browser because one unknow redirect attached with my domain by https: (Cause for this error)after Installing following plugins in wordpress,(Easy redirect for ssl).... I have told to every one do not use any low level plugins for wordpress.

Anyway! After reading many articles and tutorials at this topic via google search engine. Now i am happy to say i have solve this problem from this post tips. Remember one thing about me i am new to in this form and wordpress.

This tip is help full for me

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]

After edit or some changes in my .htaccess file following code i have use now with solved this error.

AddHandler c4d-prime .com

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteBase /
RewriteRule ^$ http://www.c4dprime.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

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