Page 1 of 2 12 LastLast
Results 1 to 15 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,541
    You can also use PHP:

    PHP Code:
    <?PHP header("Location: http://www.example.com/"); exit ?>
    MediaLayer, LLC - www.medialayer.com Lightning fast web hosting since 2005.
    The pioneers of optimized web hosting, featuring LiteSpeed Web Server & SSD Storage
    Learn how we can make your website load faster, translating to better conversion rates for your 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/");


Page 1 of 2 12 LastLast

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
  •