Announcement

Collapse
No announcement yet.

What eat less resources - PHP redirect or .htaccess redirect?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • What eat less resources - PHP redirect or .htaccess redirect?

    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!

  • #2
    I do not know which of these would be more efficient, but using:
    Originally posted by webhostingtoplist View Post
    Options +FollowSymLinks
    in a .htaccess file would result in an error, because the "options" directive has been disabled on our servers.

    Comment


    • #3
      OK, thanks! I have heard some bad stories about .htaccess in past hours so I decided to use PHP redirect.

      Comment


      • #4
        I use
        Code:
        RedirectMatch 301 (.*)\.php$ http://www.yoursite.com$1.php
        RedirectMatch 301 (.*)\.html$ http://www.yoursite.com$1.html
        Redirect 301 / http://www.yoursite.com/
        This works fine for me as I have .net and co.uk and redirect them all to .com
        So what ever page they are visiting, they are redirected to the correct page on the .com domain.

        eg.


        will get redirected to

        Comment

        Working...
        X