Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
380 views
Welcome To Ask or Share your Answers For Others

1 Answer

$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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...