当人们访问我的域名被重定向至 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.phpto 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网址
发布评论