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"
Printable View
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"
You can do that easily using a .htaccess rule (assuming you're using Apache):
Add a RewriteBase directive and/or change the redirection path as necessary.Code:RewriteEngine On
RewriteCond %{QUERY_STRING} =""
RewriteRule test.php test.php?page=index [R=302,L]
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.
i already knew how to do it in .htaccess but i was wondering if there is a way to do it in PHP
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();
}
Thank You Very Much Penagate!!!