Results 1 to 5 of 5

Thread: redirection trouble

  1. #1

    Thread Starter
    Addicted Member Beasts's Avatar
    Join Date
    Oct 2006
    Posts
    147

    redirection trouble

    hi.
    how do i make it so that if the URL is "http://mysite.com/index.php" then automatically redirect to "http://mysite.com/index.php?page=index"

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: redirection trouble

    You can do that easily using a .htaccess rule (assuming you're using Apache):

    Code:
    RewriteEngine On
    RewriteCond %{QUERY_STRING} =""
    RewriteRule test.php test.php?page=index [R=302,L]
    Add a RewriteBase directive and/or change the redirection path as necessary.
    Change R=302 to R=301 once you've got the redirection working correctly. 301 redirections are cacheable while 302s are not; 302 is thus preferred during debugging.
    Last edited by penagate; Oct 22nd, 2007 at 02:48 AM.

  3. #3

    Thread Starter
    Addicted Member Beasts's Avatar
    Join Date
    Oct 2006
    Posts
    147

    Re: redirection trouble

    i already knew how to do it in .htaccess but i was wondering if there is a way to do it in PHP

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: redirection trouble

    What's the point? It'll only be less efficient.

    Nevertheless, if you must:
    PHP Code:
    if (!isset($_GET['page']))
    {
      
    header('HTTP/1.1 301 Moved Permanently');
      
    header("Location: http://{$_SERVER['HTTP_HOST']}/index.php?page=index");
      exit();

    Last edited by penagate; Oct 22nd, 2007 at 04:22 AM.

  5. #5

    Thread Starter
    Addicted Member Beasts's Avatar
    Join Date
    Oct 2006
    Posts
    147

    Re: redirection trouble

    Thank You Very Much Penagate!!!

Posting Permissions

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



Click Here to Expand Forum to Full Width