使用.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]