首页 \ 问答 \ 使用.htaccess将所有非www重定向到www和https的www(Redirect all non-www to www for both http and https with .htaccess)

使用.htaccess将所有非www重定向到www和https的www(Redirect all non-www to www for both http and https with .htaccess)

我想将所有非www重定向到www - 如果请求是通过http它应该重定向到http://www.domain.com ,如果请求是通过https然后直接到https://www.domain.com

我在.htaccess中尝试了以下内容,但它将所有内容重定向到https

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301

我已经使用了这段代码并且它完美地解析了。 请检查一下是否正确。

RewriteEngine On
RewriteBase /
#Redirect non-www to www

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.pnrstatusbuzz.in/%{REQUEST_URI}

I want to redirect all non-www to www - if the request is through http it should redirect to http://www.domain.com, if the request is through https then direct to https://www.domain.com

I have tried the following in my .htaccess, but it redirects everything to https

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301

I have used this code and it's resolving perfectly. Please check whether it's correct or not.

RewriteEngine On
RewriteBase /
#Redirect non-www to www

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.pnrstatusbuzz.in/%{REQUEST_URI}

原文:https://stackoverflow.com/questions/21587926
更新时间:2024-03-29 13:03

最满意答案

每个docker-compose.yml都会创建自己的子网。 所以你的3个容器看不到对方。 由其他docker-compose创建的网络据说是外部的,因此您必须声明它们。 您可以使用docker network ls查看这些网络。

在docker-compose.yml文件中声明外部网络中的外部网络后,您必须定义nginx服务应使用的网络。 您应该保留default网络。

通常,docker-compose网络的默认名称是<current_dir>_default 。 因此,假设您当前的目录名为yourproject1 ,网络名称将是yourproject1_default

然后您将能够使用external_links访问您的wordpress容器(优于IP地址的IP地址)

在这里我会为nginx的docker-compose.yml文件做些什么来让他能够看到wordpress容器:

version: '2'

services:
  nginx:
    ...
    external_links:
      - your_project1_wordpress1_1:wordpress1
      - your_other_project2_wordpress2_1:wordpress2
    networks:
      - default
      - your_project1_default
      - your_other_project2_defaul



networks:
  your_project1_default:
    external: true
  your_other_project2_default:
    external: true

Each docker-compose.yml will create it's own subnet. So your 3 containers can't see each other. Networks created by other docker-compose are said to be external so you have to declare them as such. You can see these networks using docker network ls.

After declaring the external networks in your external networks in your docker-compose.yml file, you will have to define what networks should be using by the nginx service. You should keep the default network.

Usually the default name for your docker-compose network is <current_dir>_default. So suppose your current directory is called yourproject1 the network name is going to be yourproject1_default.

And then you will be able to access your wordpress containers using external_links (better than ip addresses IMO)

Here what I would do for nginx's docker-compose.yml file to make him able to see wordpress containers :

version: '2'

services:
  nginx:
    ...
    external_links:
      - your_project1_wordpress1_1:wordpress1
      - your_other_project2_wordpress2_1:wordpress2
    networks:
      - default
      - your_project1_default
      - your_other_project2_defaul



networks:
  your_project1_default:
    external: true
  your_other_project2_default:
    external: true

相关问答

更多
  • Docker 1.13.x中有一个新功能,称为Docker容器修剪 : docker docker container prune这将完成您所需要的,并且应该以相同的方式在所有平台上工作。 还有一个Docker系统修剪器 ,它将通过一个命令清理容器,映像,卷和网络。 原始答案: 有一些关于Docker清理命令的讨论。 您可以在此机票上找到有关信息: https : //github.com/dotcloud/docker/issues/928 直到该命令可用,您可以将Docker命令与其他Unix命令一起进 ...
  • 只能停止的集装箱可以列出: docker ps --filter "status=exited" 要么 docker ps -f "status=exited" Only stopped containers can be listed using: docker ps --filter "status=exited" or docker ps -f "status=exited"
  • 如果你想链接两个或两个以上的容器,你可以使用网络 。 首先创建一个网络: $ docker network create --driver bridge dev_network 现在用--net = dev_network运行这两个容器 容器1 $ docker run --security-opt=seccomp:unconfined -p 27017:27017 -p 28017:28017 --name mong --rm mong --net=dev_network 容器2 docker run ...
  • 配置文件位于/etc/rabbitmq/rabbitmq.config所以如果你使用类似的东西来挂载你自己的配置文件(我在这里使用docker-compose来设置映像) volumes: - ./conf/myrabbit.conf:/etc/rabbitmq/rabbitmq.config 应该这样做 the config file lives in /etc/rabbitmq/rabbitmq.config so if you mount your own config file with some ...
  • 有许多方法,通常涉及外部脚本或其他此类系统,通过解析json信息或获取端口映射 ,并将其传递到将使用的新容器,从一个容器收集信息(如端口映射)它连接到第一个。 文档和示例部分中有一些示例。 随着2013年10月31日发布的v0.6.5, Docker正在添加协调其中一部分的能力。 目前(2013-11-01),博客文章提供了有关如何使用它的大部分信息,但请关注文档以获取更多信息。 There are a number of ways, usually involving an external script ...
  • oracle默认侦听器将配置的主机解析为错误的IP地址: vim $ ORACLE_HOME / network / admin / listener.ora: SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe) (PROGRAM = extproc) ) ) LI ...
  • 每个docker-compose.yml都会创建自己的子网。 所以你的3个容器看不到对方。 由其他docker-compose创建的网络据说是外部的,因此您必须声明它们。 您可以使用docker network ls查看这些网络。 在docker-compose.yml文件中声明外部网络中的外部网络后,您必须定义nginx服务应使用的网络。 您应该保留default网络。 通常,docker-compose网络的默认名称是_default 。 因此,假设您当前的目录名为yourpr ...
  • Docker机器提供了一个在您的环境中设置$DOCKER_HOST的包装器。 因此,您可以检查此变量,如果已定义剥离端口号并且这是您的目标IP。 如果没有定义,您可以使用localhost 。 Docker machine provides a wrapper around setting $DOCKER_HOST in your environment. So you can check this variable, if it's defined strip off the port number an ...
  • 如果容器在重新启动时自动运行,并且您没有cron / bash配置文件/ rc.local或任何其他启动屏幕,那么这可能意味着它们是设置了--restart选项的容器。 你可以通过运行下面的命令来改变它 docker ps -q | xargs docker update --restart no docker ps -q | xargs docker stop 然后重新启动机器。 容器不应该启动。 如果他们这样做,那么你就有一些脚本在启动它们 If the containers are running ...
  • 首先,您没有使用仅数据容器。 由于您实际上正在安装主机卷,因此您的数据容器实际上并没有为您购买任何东西:您可以使用-v /path/to/volume:/var/jenkins_home轻松替换第二个容器上的--volumes-from -v /path/to/volume:/var/jenkins_home命令行选项。 其次,您不需要“启动”数据容器以便在--volumes-from引用它。 考虑: docker run --name mydata -v /data busybox true 这个容器立 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)