重定向非www到WWW网址重定向、网址、www、WWW

由网友(轮回亦思伊人)分享简介:当人们访问我的域名被重定向至http://www.mydomain.com/en/index.php 使用PHP codeI增加了以下code在.htaccess RewriteEngine叙述上选项​​+的FollowSymLinks的RewriteBase /的RewriteCond%{HTTP_HOST}!^...

当人们访问我的域名被重定向至 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']);
    出口;
}
 
js 怎么URL 重定向,和获取重定向之后的地址以及参数

在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

阅读全文

相关推荐

最新文章