从https去除WWW [英] remove www from https

查看:346
本文介绍了从https去除WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个htaccess的重写,除去WWW。从https:只有页面。我发现每一篇文章都删除WWW的所有网页。

什么我需要在.htaccess做到这一点?

https://www.mydomain.com 应的 https://mydomain.com

https://mydomain.com 应该保持的 https://mydomain.com

http://www.mydomain.com 应该保持的 http://www.mydomain.com

http://mydomain.com 应该保持的 http://mydomain.com

我已经能够得到以下工作:

 的RewriteCond%{HTTPS}等^关于(S)|
HTTP的RewriteCond%1://%{HTTP_HOST}%{REQUEST_URI} ^(HTTPS://)WWW \(+)[NC]。
重写规则^%1%2 [L,R,QSA]
 

但这种重写HTTPS和HTTP

下面是我当前的.htaccess

  SETENV DEFAULT_PHP_VERSION 5

RewriteEngine叙述上
RewriteOptions MaxRedirects = 1

#您可能需要取消注释以下行上一些托管环境,
#例如在unitedhosting.co.uk
#的RewriteBase /


#下面的行已被以排除webim加入
#从LemonStand URL处理目录。
的RewriteCond%{REQUEST_URI}!^ / webim



#
#不允许执行任何PHP脚本
#

重写规则^(。*)。PHP $的index.php [L]

#
#下面的部分会自动添加斜线到所有网址
#

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI}!(\ [A-ZA-Z0-9] {1,5} | /)$
的RewriteCond%{HTTP:X请求的-WITH} ^(XMLHtt prequest)$!
的RewriteCond%{REQUEST_METHOD} ^!HEAD $
的RewriteCond%{REQUEST_METHOD}!^ POST $
重写规则(。*)([^ /])$%{REQUEST_URI} / [R = 301,L]

#下面的行已被以排除webim加入
#从LemonStand URL处理目录。
的RewriteCond%{REQUEST_URI}!^ / webim


#
#产品文件下载网址
#

重写规则(^ download_product_file /.*)的index.php?Q = / $ 1 [L,QSA]

#下面的行已被以排除webim加入
#从LemonStand URL处理目录。
的RewriteCond%{REQUEST_URI}!^ / webim


#
#管理区文件下载网址
#

重写规则ls_backend /文件/得到/(.*)的index.php?Q = / backend_file_get / $ 1 [L]

#下面的行已被以排除webim加入
#从LemonStand URL处理目录。
的RewriteCond%{REQUEST_URI}!^ / webim


#
#所有其他请求
#

的RewriteCond%{REQUEST_URI}(\(ICO。| JS | JPG | GIF | CSS | PNG |瑞士法郎| FLV | TXT | XML | XLS | PDF | EOT | WOFF | TTF | SVG | MP4)$)!
的RewriteCond%{REQUEST_URI}!(phproad / thirdpart /.*)
重写规则^(。*)$的index.php?Q = / $ 1 [L,QSA]

的ErrorDocument 404找不到文件

#
#PHP配置
#

< IfModule mod_php5.c>
的php_flag session.auto_start关闭
php_value session.cookie_lifetime 31536000
的php_flag session.use_cookies上
的php_flag session.use_only_cookies上
php_value session.name FWCSESSID

的php_flag short_open_tag的值为上
的php_flag asp_tags上

的php_flag magic_quotes_gpc的关
php_value date.timezone GMT

php_value的post_max_size 100M
php_value的upload_max_filesize 100M

php_value memory_limit的264M
< / IfModule>
 

解决方案

  RewriteEngine叙述上

#检查你的443端口和主机名开头WWW
的RewriteCond%{SERVER_PORT} ^ 443
的RewriteCond%{HTTP_HOST} ^ WWW \。

#重定向到域,而无需在WWW
重写规则的https(*)://example.com$1 [L,R QSA]
 

I'm trying to find a htaccess rewrite to remove www. from https: pages only. Every article I've found removes www for all pages.

What do I need in .htaccess to do this?

https://www.mydomain.com should be https://mydomain.com

https://mydomain.com should remain https://mydomain.com

http://www.mydomain.com should remain http://www.mydomain.com

http://mydomain.com should remain http://mydomain.com

I've been able to get the following working:

RewriteCond %{HTTPS}s ^on(s)|
RewriteCond http%1://%{HTTP_HOST}%{REQUEST_URI} ^(https?://)www\.(.+) [NC]
RewriteRule ^ %1%2 [L,R,QSA]

But this rewrites both https and http

Here is my current .htaccess

SetEnv DEFAULT_PHP_VERSION 5

RewriteEngine on
RewriteOptions MaxRedirects=1

# You may need to uncomment the following line on some hosting environments, 
# for example on unitedhosting.co.uk
# RewriteBase /


# The following line has been added in order to exclude the webim
# directory from the LemonStand URL processing.
RewriteCond %{REQUEST_URI} !^/webim



#
# Do not allow executing any PHP scripts
#

RewriteRule ^(.*).php$ index.php [L]

#
# The following section automatically adds a trailing slash to all URLs
#

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteCond %{HTTP:X-REQUESTED-WITH} !^(XMLHttpRequest)$
RewriteCond %{REQUEST_METHOD} !^HEAD$ 
RewriteCond %{REQUEST_METHOD} !^POST$ 
RewriteRule (.*)([^/])$ %{REQUEST_URI}/ [R=301,L]

# The following line has been added in order to exclude the webim
# directory from the LemonStand URL processing.
RewriteCond %{REQUEST_URI} !^/webim


#
# Product files downloading URL
#

RewriteRule (^download_product_file/.*) index.php?q=/$1 [L,QSA]

# The following line has been added in order to exclude the webim
# directory from the LemonStand URL processing.
RewriteCond %{REQUEST_URI} !^/webim


#
# Administration Area file downloading URL
#

RewriteRule ls_backend/files/get/(.*) index.php?q=/backend_file_get/$1 [L]

# The following line has been added in order to exclude the webim
# directory from the LemonStand URL processing.
RewriteCond %{REQUEST_URI} !^/webim


#
# All other requests
#

RewriteCond %{REQUEST_URI} !(\.(ico|js|jpg|gif|css|png|swf|flv|txt|xml|xls|pdf|eot|woff|ttf|svg|mp4)$)
RewriteCond %{REQUEST_URI} !(phproad/thirdpart/.*)
RewriteRule ^(.*)$ index.php?q=/$1 [L,QSA]

ErrorDocument 404 "File not found"

#
# PHP configuration
#

<IfModule mod_php5.c>
php_flag session.auto_start off
php_value session.cookie_lifetime 31536000
php_flag session.use_cookies on
php_flag session.use_only_cookies on
php_value session.name FWCSESSID

php_flag short_open_tag on
php_flag asp_tags on

php_flag magic_quotes_gpc off
php_value date.timezone GMT

php_value post_max_size 100M
php_value upload_max_filesize 100M

php_value memory_limit 264M
</IfModule>

解决方案

RewriteEngine On

# Check that you're on port 443 and the hostname starts with www
RewriteCond %{SERVER_PORT} ^443
RewriteCond %{HTTP_HOST} ^www\.

# Redirect to domain without the www
RewriteRule (.*) https://example.com$1 [L,R,QSA]

这篇关于从https去除WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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