Time2Dine.co.nz is Online Restaurant Booking
 
 New Zealand Restaurants Forum
Restaurant Forum | Contact Time2Dine | Book Online & Save | About Time2Dine

Go Back   New Zealand Restaurants & Food Forum > Search Engine Optimisation > Google
Register

Reply
 
LinkBack Thread Tools
  #1  
Old 1st Jun 06, 11:37 AM
T2DMan's Avatar
Administrator
 
Join Date: Apr 2004
Location: Auckland, New Zealand
Posts: 7,839
T2DMan is on a distinguished road
Default index.php to root redirects

As well as non www to www redirects, there is a need for redirects from index.php or index.html to the root of a domain.

either:
www.domain.com/index.php to www.domain.com or
www.domain.com/directory/index.php to www.domain.com/directory/

.htaccess
[PHP]
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*\/index\.php
RewriteRule ^(.*)index\.php$ http://www.domain.com [R=301,L]

[/PHP]

If you add the following to the first php of every index.php file, it will 301 redirect to the root. You can create a function or an include file that includes the following code:


[PHP]
if(preg_match("/[index.php]$/",$_SERVER[REQUEST_URI]))
{

$url="http://".$_SERVER[HTTP_HOST].preg_replace("/(index.php)$/","",$_SERVER[REQUEST_URI]);
$sapi=php_sapi_name();
if (PHP_VERSION >= '4.3.0')
{
header("Location: $url", 0, 301);
}
else if ($sapi == 'cgi' OR $sapi == 'cgi-fcgi')
{
header("Location: $url");
// Call the status header after Location so we are sure to wipe out the 302 header sent by PHP
header('Status: 301 Moved Permanently');
}
else
{
header("Location: $url");
header('HTTP/1.1 301 Moved Permanently');
}
}
[/PHP]



Please test that it works, no guarantees for your particular server configuration.

The following script will give the values of all your server variables on your system:

[PHP]
<pre>
<? print_r($_SERVER);?>
</pre>
[/PHP]

Last edited by T2DMan; 28th Jun 07 at 12:16 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
301 redirects T2DMan Google 10 21st Oct 10 11:54 PM
non www to www 301 redirects T2DMan Google 6 29th May 10 06:38 AM
ASP 301 redirects T2DMan Google 1 4th Aug 06 01:25 PM



Powered by: vBulletin Copyright ©2000 -2012, Jelsoft Enterprises Limited.
Search Engine Friendly URLs by vBSEO 3.2.0
© 2010 Time2Dine