重定向非www到WWW网址

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

当人们访问我的域名被重定向至 www.mydomain/en/index.php 使用PHP codeI增加了以下code在.htaccess

RewriteEngine叙述上 选项​​+的FollowSymLinks 的RewriteBase / 的RewriteCond%{HTTP_HOST}!^ WWW \。 (。*)重写规则^ $ HTTP://www.% {HTTP_HOST} / $ 1 [R = 301,L] 永久重定向/pages/abc-123.html www.mydomain/en/page-a1/abc.php

重定向人的非WWW到www

不过用户可以通过键入这两个 mydomain/en/page-a1/abc访问。 PHP 和 www.mydomain/en/page-a1/abc。 PHP 网址

有谁知道方法完全重定向到 www.mydomain/en/页A1 / abc.php 即使用户输入 www.mydomain /en/page-a1/abc.php ,并禁止访问的URL加www。

解决方案

$ PROTOCOL =(@ $ _ SERVER [HTTPS] ==上)? https://开头:HTTP://; 如果(SUBSTR($ _ SERVER ['HTTP_HOST'],0,4)!=='WWW'){     头('位置:''。$ _ SERVER $ protocol.'www'。$ _ SERVER ['HTTP_HOST']。'/ ['REQUEST_URI']);     出口; }

在PHP

When people access my domain it is redirected to www.mydomain/en/index.php using php code.I added the following code in .htaccess

RewriteEngine on Options +FollowSymlinks RewriteBase / RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ www.%{HTTP_HOST}/$1 [R=301,L] RedirectPermanent /pages/abc-123.html www.mydomain/en/page-a1/abc.php

to redirect people from non www to www,

Still users can access by typing both mydomain/en/page-a1/abc.php and www.mydomain/en/page-a1/abc.php URLs

Does anyone know the method to completely redirect to www.mydomain/en/page-a1/abc.php even if user typed www.mydomain/en/page-a1/abc.php, and prohibit accessing URLs without www.

解决方案

$protocol = (@$_SERVER["HTTPS"] == "on") ? "" : ""; if (substr($_SERVER['HTTP_HOST'], 0, 4) !== 'www.') { header('Location: '.$protocol.'www.'.$_SERVER['HTTP_HOST'].'/'.$_SERVER['REQUEST_URI']); exit; }

in php

更多推荐

重定向非www到WWW网址

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

发布评论

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

>www.elefans.com

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