使用.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
最满意答案
每个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 beyourproject1_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 ...
-
如何在Docker容器中配置rabbitmq.config?(How to configure rabbitmq.config inside Docker containers?)[2024-02-17]
配置文件位于/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 ... -
Docker - 几个容器(Docker - few containers)[2023-11-11]
有许多方法,通常涉及外部脚本或其他此类系统,通过解析json信息或获取端口映射 ,并将其传递到将使用的新容器,从一个容器收集信息(如端口映射)它连接到第一个。 文档和示例部分中有一些示例。 随着2013年10月31日发布的v0.6.5, Docker正在添加协调其中一部分的能力。 目前(2013-11-01),博客文章提供了有关如何使用它的大部分信息,但请关注文档以获取更多信息。 There are a number of ways, usually involving an external script ... -
Docker容器之间的JDBC连接(docker-compose)(JDBC connection between Docker containers (docker-compose))[2021-08-20]
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容器/ VM的主机名一致吗?(Consistent hostname for Docker containers/VM across platforms?)[2022-12-08]
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 这个容器立 ...