我想重定向所有的HTTP请求到https,并且所有WWW要求非www

编程入门 行业动态 更新时间:2024-10-28 14:33:36
本文介绍了我想重定向所有的HTTP请求到https,并且所有WWW要求非www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

下面是我目前的.htaccess文件:

Here is my current .htaccess file:

<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule ^ %{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php </IfModule>

我要重定向所有的HTTP请求到https,并且所有WWW要求非www,所有文件请求到index.php

I want to redirect all http requests to https, and all www requests to non-www, and all file requests to index.php

例如:

www.example 到的 example

www.example 到的 example

example/file.php 到的 example/index.php

一切似乎是工作以外的WWW部分..任何帮助吗?

Everything seems to be working except the www part.. Any help please?

推荐答案

您可以添加处理WWW部分其他规则

You can add an additional rule dealing with the www part

RewriteCond %{HTTP_HOST} ^www\.(.+)$ RewriteRule ^ %1%{REQUEST_URI} [L,R]

借助 的RewriteCond 捕获 WWW之后的一切。并使用了的 重写规则 为%1 。

当一切都按你期望的那样,你可以修改研究到 R = 301 。

When everything works as you expect, you can change R to R=301.

永远不要的测试与 301 启用,看到这个答案 提示调试的.htaccess重写规则的 了解详细信息。

Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

更多推荐

我想重定向所有的HTTP请求到https,并且所有WWW要求非www

本文发布于:2023-11-01 19:37:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我想   重定向   HTTP   www   WWW

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!