删除www站点范围,在某些目录上强制https,在其余目录上删除http?

时间:2022-01-15 11:20:51

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

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

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

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

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

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

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

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

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:

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

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

@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

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?

导航到http:// example / login仍然会转到http://example/index.php,它应该转到https:// example / login我的订单是否有错?

4 个解决方案

#1


24  

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.

您还可能希望添加一些其他条件,以仅更改GET和HEAD请求上的协议,但不更改POST请求。

#2


1  

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>

#3


0  

remove www (tested):

删除www(已测试):

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]

#4


0  

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.

阅读完所有发布时间后,我已成功跟踪错误:我的网站(c4dprime.com)附加了https:在mozilla firefox浏览器中。谷歌和互联网探索显示域名地址为http :( firefox中的真正问题)我不想要https:对于我的域在任何浏览器中,因为一个未知的重定向附加到我的域通过https :(导致此错误)安装后wordpress中的插件,(轻松重定向ssl)....我告诉每个人都不要使用任何低级插件进行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.

无论如何!通过谷歌搜索引擎阅读了这个主题的许多文章和教程。现在我很高兴地说我已经从这个帖子提示解决了这个问题。记住关于我的一件事我是这个形式和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.

编辑或我的.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

#1


24  

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.

您还可能希望添加一些其他条件,以仅更改GET和HEAD请求上的协议,但不更改POST请求。

#2


1  

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>

#3


0  

remove www (tested):

删除www(已测试):

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]

#4


0  

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.

阅读完所有发布时间后,我已成功跟踪错误:我的网站(c4dprime.com)附加了https:在mozilla firefox浏览器中。谷歌和互联网探索显示域名地址为http :( firefox中的真正问题)我不想要https:对于我的域在任何浏览器中,因为一个未知的重定向附加到我的域通过https :(导致此错误)安装后wordpress中的插件,(轻松重定向ssl)....我告诉每个人都不要使用任何低级插件进行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.

无论如何!通过谷歌搜索引擎阅读了这个主题的许多文章和教程。现在我很高兴地说我已经从这个帖子提示解决了这个问题。记住关于我的一件事我是这个形式和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.

编辑或我的.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