使用.htaccess从http重定向到https而不使用www [英] Redirect from http to https without www using .htaccess

查看:59
本文介绍了使用.htaccess从http重定向到https而不使用www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有基于PHP和Apache的应用程序.如果请求的链接不是目录或文件,则所有请求都将进入index.php文件.我想将所有请求从http重定向到https,而没有www.

I have application based on PHP and Apache. If requested link is not directory or file, all requests go to index.php file. I wanna redirect all requests from http to https and without www.

对我有效的链接:

  1. https://someaddress.org

从以下对我无效的链接开始(对不起,我的声誉很小,我无法发布更多2个链接):

Started from following links invalid for me(sorry my reputation is very small and i cant post more 2 links):

  1. http://
  2. http://www .
  3. www.

我的htaccess看起来像这样

My htaccess looks like that

AddDefaultCharset UTF-8

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php [L]

如何在没有www的情况下重定向到https?

How i can do redirects to https and without www?

推荐答案

对于http->httpwww删除还有另一条规则:

Have another rule for http->http and www removal:

AddDefaultCharset UTF-8

RewriteEngine on
RewriteBase /

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://someaddress.org%{REQUEST_URI} [L,NE,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

这篇关于使用.htaccess从http重定向到https而不使用www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆