重定向非www到WWW网址 [英] Redirect Non-WWW to WWW URLs
问题描述
当人们访问我的域名被重定向至 http://www.mydomain.com/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 http://www.mydomain.com/en/page-a1/abc.php
重定向人的非WWW到www
不过用户可以通过键入这两个 http://mydomain.com/en/page-a1/abc访问。 PHP 和 http://www.mydomain.com/en/page-a1/abc。 PHP 网址
有谁知道方法完全重定向到 http://www.mydomain.com/en/页A1 / abc.php 即使用户输入 http://www.mydomain.com /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 http://www.mydomain.com/en/index.php using php code.I added the following code in .htaccess
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RedirectPermanent /pages/abc-123.html http://www.mydomain.com/en/page-a1/abc.php
to redirect people from non www to www,
Still users can access by typing both http://mydomain.com/en/page-a1/abc.php and http://www.mydomain.com/en/page-a1/abc.php URLs
Does anyone know the method to completely redirect to http://www.mydomain.com/en/page-a1/abc.php even if user typed http://www.mydomain.com/en/page-a1/abc.php, and prohibit accessing URLs without www.
$protocol = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
if (substr($_SERVER['HTTP_HOST'], 0, 4) !== 'www.') {
header('Location: '.$protocol.'www.'.$_SERVER['HTTP_HOST'].'/'.$_SERVER['REQUEST_URI']);
exit;
}
in php
这篇关于重定向非www到WWW网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!