Results 1 to 25 of 25
  1. #1

    index.php redirect

    Hi all,

    I have a script that is locked to my domain. It is no longer supported and therefore I cannot change this domain lock. The license requires access to the script by having a www in the address not just http

    Therefore users trying to access the script without www in the address are displayed an error message. Is there a code I can insert into the index page so if the user accesses it without www in the address it will redirect to the same index page but by including www in the address.

    Sorry I cant be more specific, currently im not certified to post urls so its made it a little hard to explain my situation easily.

    Im hosted on a windows server so believe I cannot use .htaccess, any help will be greatly appreciated as my php knowledge isnt very good.

    Thanks

  2. #2
    Join Date
    Jan 2005
    Location
    Leeds, England
    Posts
    183
    Welcome to WHT!

    all i can suggest is you put an index.html page in there along with it with meta tags in that redirect it to www.

    Code:
    <html><head><META 
    http-equiv="refresh" content="2;URL=http://www.yourdomain.com/index.php"></head><body> <center>If you are not redirected to the site within 2 seconds <a href="http://www.yourdomain.com/index.php">Click Here</a></body></html>
    there's the html code for the whole page.

    there is also a way to do it via the php script however you haven't posted the source for ti so we can't really help you with something to put in the php script

    also this thread should be in the programming discussion forum as it's not a tutorial
    Last edited by Omega-Mark; 08-28-2006 at 08:56 AM.

  3. #3
    Join Date
    Dec 2004
    Location
    New York, NY
    Posts
    10,574
    You can also use PHP:

    PHP Code:
    <?PHP header("Location: http://www.example.com/"); exit ?>
    MediaLayer, LLC - www.medialayer.com Learn how we can make your website load faster, translating to better conversion rates for your business!
    The pioneers of optimized web hosting, featuring LiteSpeed Web Server & SSD Storage - Celebrating 10 Years in Business

  4. #4
    Thanks to the both of you for replying.

    This was my first post on this forum and therefore could not post direct links or use the PHP tags, I figured it would be abit messy if I just posted the contents of the index.php straight into the thread post.

    Do you just need the first few lines or the whole file (635 lines) ?

    A index.html file wouldnt be beneficial really as it wouldn't solve the problem if the user typed in the address but only omitted the www part.

    Sorry for posting in the wrong thread, figured programming discussion would be the most likely place, didnt realise I was in the tutorial sub-forum though, could a mod please move this to the relevant location please.

    layer0: Do I simply paste that code into the index.php file and enter the location I want it to redirect to?

    Thanks again to you both

  5. #5
    I have also posted a support ticket to my webhost, although its strictly not his responsibility to support this kind of question he is a helpful guy and may sort something out for me.

    Any other suggestions would be appreciated. The script does call a config file, perhaps a code could be placed in there to avoid looping in the index file.

  6. #6
    Join Date
    Jan 2005
    Location
    Leeds, England
    Posts
    183
    Quote Originally Posted by erystiva
    Thanks to the both of you for replying.

    This was my first post on this forum and therefore could not post direct links or use the PHP tags, I figured it would be abit messy if I just posted the contents of the index.php straight into the thread post.

    Do you just need the first few lines or the whole file (635 lines) ?

    A index.html file wouldnt be beneficial really as it wouldn't solve the problem if the user typed in the address but only omitted the www part.

    Sorry for posting in the wrong thread, figured programming discussion would be the most likely place, didnt realise I was in the tutorial sub-forum though, could a mod please move this to the relevant location please.

    layer0: Do I simply paste that code into the index.php file and enter the location I want it to redirect to?

    Thanks again to you both
    just paste the code that layer0 suggested tot he top of your script.

  7. #7
    Thanks for confirming that for me Omega-Mark

  8. #8
    .. or you can use .htaccess redirect,
    redirect 301

  9. #9
    Join Date
    Jun 2003
    Posts
    629
    an htaccess redirect is probably the quickest and easiest way to do that, just add
    Redirect / http : / / www dot whatever you want dot com

    (obviously take out the spaces in the url)

  10. #10
    Few Suggestions:-
    I Report this Bug to Developer of this system rather your hosting company. It is one min job to solve.
    II Rename the Main Index.php to anything.php and add this code
    [PHP
    <?PHP
    // filename: index.php
    header("Location: http://www.example.com/anything.php");
    ?>
    [/PHP]

  11. #11
    Add code below to top of index.php or config.php file:

    PHP Code:

    if ($_SERVER['HTTP_HOST']!="www.YourDomain.com") {
     
    header("location: http://www.YourDomain.com");

    Website Hosting by Rackset
    Professional, Affordable, Reliable

    Web Hosting Provider

  12. #12

    Oh

    Quote Originally Posted by RACKSET
    Add code below to top of index.php or config.php file:

    PHP Code:

    if ($_SERVER['HTTP_HOST']!="www.YourDomain.com") {
     
    header("location: http://www.YourDomain.com");

    If we use upper script for this:

    PHP Code:
     if ($_SERVER['HTTP_HOST']="www.sub-domain.YourDomain.com") {
     
    header("location: http://www.YourDomain.com/sub-domain/");

    Can you tell me "it will run"?
    << Please see the Rules page for signature limitations. >>

  13. #13
    I have not tested that, but you can check it and please send the result.
    Website Hosting by Rackset
    Professional, Affordable, Reliable

    Web Hosting Provider

  14. #14
    Join Date
    Mar 2006
    Posts
    961
    http://ca3.php.net/preg_match

    Example 3 is also a very good test result.

  15. #15
    Join Date
    Mar 2006
    Posts
    961
    Further to what I stated above,

    I would change:

    PHP Code:
    if ($_SERVER['HTTP_HOST']="www.sub-domain.YourDomain.com") {
     
    header("location: http://www.YourDomain.com/sub-domain/");

    for:

    PHP Code:
    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
     
    header("location: https://www.YourDomain.com/sub-domain/");
     } else {
     
    header("location: http://www.YourDomain.com/sub-domain/");


  16. #16
    (I know this thread is kinda old, but I think this is an important note for people finding this thread in the future)

    What all the above ones have done will indeed redirect the page, however search engines will still see it as a seperate page from the one you're redirecting it to.

    Adding this to the end of the "header" function will make sure search engines know to treat it as the same page - which can greatly help with your page rank, backlink count, etc.
    , TRUE, 301);
    eg:
    PHP Code:
    header("location: [blahblahblah]"TRUE301); 
    "301" HTTP response code means moved permanently, FYI.

  17. #17

    Re:

    Excellent, yp it is the most easiest one.

  18. #18
    Oh, my site has been gone this way but I never though it take a good effect like that.

    By the way, thank for your informations,
    << Please see the Rules page for signature limitations. >>

  19. #19
    I wish to see tutorial for redirection by IP-address (by country) in here..

  20. #20
    better to use php code

  21. #21
    Good info! htaccess can also be used to redirect pages with 301 redirects. This is the way that I have been doing it recently.

  22. #22
    What you could do is rename the index.php to something like home.php
    And replace index.php with redirect to to home.php or use htaaccess. Such as redirect /index.php www.yourdomain.com/home.php.

  23. #23
    301 Redirect htaccess = best solution

  24. #24
    Wow its a good thing to know thanks Boss

  25. #25

    crea8ivedesign.com

    hi
    yes its code its currupt they can verify by phpcake

    regards
    crea8ivedesign.com

  26. Newsletters

    Subscribe Now & Get The WHT Quick Start Guide!

Related Posts from theWHIR.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •