PHP Newbie Question

Discussion in 'PHP' started by walterhnry, Jan 17, 2012.

  1. #1
    Below is my baseurl configuration:

    $config['baseurl'] = 'http://www.praymylife.com';

    All of the page functions work when the user is using the "www." extension. But if the user visits the page with out the "www." extensions the page functions do not work.


    Please help!

    Thanks

    Walter
     
    walterhnry, Jan 17, 2012 IP
  2. yho_o

    yho_o Well-Known Member

    Messages:
    354
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    #2
    i do not fully get it but anyway, u may try to do it with .htaccess

    
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    
    
    Code (markup):
     
    yho_o, Jan 17, 2012 IP
  3. walterhnry

    walterhnry Greenhorn

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    yho_o

    Thank you for your response... Is there any other way to fix issue??? Is there a line of code that I can add to my config page??? My understanding is that the .htaccess file is for when you have limited access to the server...

    Thanks Again
     
    walterhnry, Jan 18, 2012 IP
  4. yho_o

    yho_o Well-Known Member

    Messages:
    354
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    #4
    .htaccess has tons of uses, but anyway here you're php code put it in your config

    
    <?php
    if (substr($_SERVER['HTTP_HOST'], 0, 4) !== 'www.') {
        header('Location: http://www.praymylife.com');
    }
    ?>
    
    PHP:
     
    yho_o, Jan 18, 2012 IP
  5. yafi_hostinizer

    yafi_hostinizer Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That's what I would use. .htaccess definitely rocks and does a lot of things for you if you know how to use it.

     
    yafi_hostinizer, Jan 18, 2012 IP
  6. walterhnry

    walterhnry Greenhorn

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #6
    yho_o

    You are the man!!! I ended up using the .htaccess code you provided and it worked!!! I misunderstood the uses of that file... But then again that is why Im the newb and you're the guru...

    Thanks Again...



    Thanks, yafi_hostinizer
     
    walterhnry, Jan 19, 2012 IP
  7. yho_o

    yho_o Well-Known Member

    Messages:
    354
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    #7
    you welcome buddy, glad it helped :)

     
    yho_o, Jan 20, 2012 IP