|
-
Oct 22nd, 2007, 02:26 AM
#1
Thread Starter
Addicted Member
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"
-
Oct 22nd, 2007, 02:44 AM
#2
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.
-
Oct 22nd, 2007, 03:05 AM
#3
Thread Starter
Addicted Member
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
-
Oct 22nd, 2007, 04:17 AM
#4
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.
-
Oct 23rd, 2007, 08:33 AM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|