|
|
#1
| ||||
| ||||
|
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. |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
| | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 301 redirects | T2DMan | 10 | 21st Oct 10 11:54 PM | |
| non www to www 301 redirects | T2DMan | 6 | 29th May 10 06:38 AM | |
| ASP 301 redirects | T2DMan | 1 | 4th Aug 06 01:25 PM | |