Hello,
currenty, I use PHP to redirect users from http://mydomain.com to http://www.mydomain.com. But using .htaccess seems to be easier (so I don't need to copy the php code to all files). But I am not sure how this affects CPU usage. Do you have any idea what solution is better?
Now, I am using this:
<?php
if (strpos($_SERVER['HTTP_HOST'],"www") === false) {
$url_presmerovat='http://www.'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$url_presmerovat);
header('Connection: close');
}
?>
...this piece of PHP code is in all files.
I have found 2 .htaccess solutions how to do the same:
Solution 1:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
Solution 2:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,QSA,L]
...I don't understand what does "Options +FollowSymLinks" mean (and I didn't search for it because I don't need to know what does it mean ) but I am really interested to know what is the best solution for lower CPU usage.
Thanks!
currenty, I use PHP to redirect users from http://mydomain.com to http://www.mydomain.com. But using .htaccess seems to be easier (so I don't need to copy the php code to all files). But I am not sure how this affects CPU usage. Do you have any idea what solution is better?
Now, I am using this:
<?php
if (strpos($_SERVER['HTTP_HOST'],"www") === false) {
$url_presmerovat='http://www.'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$url_presmerovat);
header('Connection: close');
}
?>
...this piece of PHP code is in all files.
I have found 2 .htaccess solutions how to do the same:
Solution 1:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
Solution 2:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,QSA,L]
...I don't understand what does "Options +FollowSymLinks" mean (and I didn't search for it because I don't need to know what does it mean ) but I am really interested to know what is the best solution for lower CPU usage.
Thanks!
Comment