从 https 中删除 www

2023-12-05

我正在尝试找到一个 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 ^on(s)|
RewriteCond http%1://%{HTTP_HOST}%{REQUEST_URI} ^(https?://)www\.(.+) [NC]
RewriteRule ^ %1%2 [L,R,QSA]

但这重写了 https 和 http

这是我当前的 .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]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 https 中删除 www 的相关文章

随机推荐

  • 在饼图上放置标签

    我想将标签放在饼图上 而不是图例中 换句话说 我希望政党的名称显示在图表的中心而不是右侧 我该怎么做 样本 DF gt data party party 1 20 1 Independents Independents Independen
  • Pyinstaller:图像无法提取

    我运行构建命令 一切似乎都正确构建 直到我尝试启动 exe 并弹出此消息 这是我的规范文件 我不确定为什么它似乎将文件路径与两个图像结合在一起 block cipher None a Analysis TripCalc py pathex
  • 搜索延迟加载 jQuery 幻灯片或:黑客交叉幻灯片

    我正在尝试使用 jquery 幻灯片来显示来自 flickr 淡入淡出和滚动的图像 一切工作正常 除了我真的需要延迟加载图像 只需按需加载图像 我目前正在使用 jquery cross slide http tobia github com
  • -10 到 10 之间的正则表达式,最多保留 1 位小数

    我有一个 C Web 应用程序 其中有一个控件 我想向其中添加正则表达式 但由于我对正则表达式毫无用处 所以我希望有人能够帮助我 我想要一个正则表达式 它将接受 10 到 10 之间的所有值 并允许最多 1 个可选的小数位 成功输入 1 2
  • 动态 tableView 高度的布局不明确

    我有一个 viewController 我想在里面有两个 1 tableView 和 1 childViewController tableView 不可滚动且具有动态单元格高度 我使用的是 tableView 所以我可以折叠行 child
  • 在 Jbutton 启用之前要填充多个 Jtextfields

    您好 我非常需要一些帮助 我已经在 jbutton 启用之前搜索要填充的 Jtextfield 大多数人使用 DocumentListener 来确定 Jtextfield 是否正在填充 我尝试了 DocumentListener 并且它有
  • 无法分配给操作员

    i 0 num 0 while i lt 1000 if i 3 and i 5 0 num i num lt Adding Up Numbers Divisable by 3 5 i 1 print num Error 无法分配给操作员
  • 在 JSON.NET 中将整数序列化为十六进制

    JSON NET 支持反序列化十六进制数 e g 0xffff 但是怎么样序列化 以下有效 但似乎太复杂 public sealed class HexJsonConverter JsonConverter public override
  • java Regex - 分割但忽略引号内的文本?

    仅使用正则表达式方法 方法 String replaceAll 和 ArrayList 如何将字符串拆分为标记 但忽略引号内存在的分隔符 分隔符是非字母数字或引用文本的任何字符 例如 字符串 你好 世界 这个 有两个令牌 应该输出 hell
  • Google Cloud CDN 以存储桶为后端签署 cookie

    作为替代方案签名网址带有 url 前缀 我试图获取签名cookie在职的 Google Cloud CDN 设置了一个后端存储桶 该存储桶已配置并适用于标准签名网址 使用这些去例子我在nodejs typescript 中实现了一个cook
  • 使用 -lpthread 标志时对“pthread_init”的未定义引用:

    我正在编译使用 gcc o outfile infile c lpthread 唯一未定义的参考是pthread init 我尝试过使用 pthread代替 lpthread 根据网上的一些建议 I am包括
  • 更改 Firemonkey StringGrid 中的文本大小

    如何更改 stringgrid 标题中的文本大小 你可以写一个OnApplyStyleLookup事件处理程序与此类似 procedure TForm1 StringGrid1ApplyStyleLookup Sender TObject
  • 从代码隐藏中打开 jQuery 对话框

    所以我必须从代 码隐藏中显示一个 jquery UI 对话框 我已经尝试了一切 this this this 并且还更改了这些答案以测试它是否适用于我但不起作用 我使用第一个解决方案 因为它是有组织的 如果我使用alert whatever
  • 使用默认触发器在窗口中消耗无限数据

    我有一个Pub Sub主题 订阅 并希望在一个订阅中消费和聚合无限数据Dataflow 我使用固定窗口并将聚合写入 BigQuery 读取和写入 没有窗口和聚合 工作正常 但是 当我将数据通过管道传输到固定窗口 以计算每个窗口中的元素 时
  • 如何在 OCaml 中使用列表实现二叉堆?

    我正在实施一个binary heap在 OCaml 中使用列表 只是为了提高我的 OCaml 技能 我觉得使用列表非常困难 经过两天的努力 我必须来这里寻求建议和提示 到目前为止 这是我的想法 显然我不能使用原来的array based使用
  • Android - AutoCompleteTextView 仅在退格时有效

    我有一个AutoCompleteTextView当用户键入时动态更新建议列表 我的问题是 当我输入时 列表会更新 但下拉列表不会显示 但是当我删除一个字符 退格键 时 会出现下拉菜单 我什至尝试明确地调用autoText showDropD
  • Python Tkinter 坐标函数不会在循环内移动画布对象

    我有一个函数 它从文本文件中读取位置 解析它们 然后使用 coords 函数将相应的对象移动到 tkinter 画布上列出的位置 正在从文件中读取数据并正确解析数据 但由于某种原因 coords 函数仅将对象移动到循环的最后一次迭代中文件中
  • WordPress:一页滚动 JQuery 脚本不起作用?

    尝试创建一个简单的一页滚动 在 WordPress 中 我有这样的导航标签 a href contact Contact a a href about About a 两个链接对应的 div 是这样的 div class bg 1 wrap
  • Grails 安全插件自定义重定向

    我是 Groovy 和 Grails 的新手 我使用 Spring Security 插件使用数据库请求的请求映射开发了一个应用程序 我想要根据角色自定义重定向到主页 如果用户是 ROLE ADMIN 他将被重定向到视图 adminUser
  • 从 https 中删除 www

    我正在尝试找到一个 htaccess 重写来删除 www 仅来自 https 页面 我发现的每篇文章都删除了所有页面的 www 我需要在 htaccess 中添加什么来执行此操作 https www mydomain com应该https