Forum Moderators: phranque
I'm thinking to use this php code placed into the web root index page:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ./info/about_us.php");
exit;
?>
concerning SE, is it better to have a 301 on my htaccess, rather than an empty index page with just such code?
is 301 the best solution for SE?
sorry for my ignorance, your suggestions will be much appreciated.
Thanks,
tito
The root index page is the most important on the site. It should directly deliver content. As for what you are actually doing, it is very bad form for the root index page to redirect to an internal URL.
What you should do is rewrite this, so that the user sees the same URL they requested, but the server gets the information from some other place, without exposing what that internal filepath actually is.
# Set Up
Options +FollowSymLinks
RewriteEngine on
# Redirect direct requests for /info/about.php (www or non-www) to "/" at www to prevent Duplicate Content
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /info/about.php\ HTTP/
RewriteRule ^info/about.php http://www.domain.eu/ [R=301,L]
# Redirect any www or non-www index filename to "/" at www & preserve folders
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.(html?¦php¦asp¦cfm)\ HTTP/
RewriteRule ^(.*)index\.(html?¦php¦asp¦cfm)$ http://www.domain.eu/$1 [R=301,L]
# Redirect all non-www to www & preserve filepath
RewriteCond %{HTTP_HOST} ^domain\.eu [NC]
RewriteRule ^(.*)$ http://www.domain.eu/$1 [R=301,L]
# REWRITE for "/" requests, actually get content from /info/about.php
RewriteCond %{REQUEST_URI} ^$
RewriteRule ^$ /info/about.php [L]
In these final two lines I am not sure that ^$ is the best thing to use. Something else might be better.
As you can see, there is much more to this that your original basic requirement. You also need to avoid duplicate content. All redirects should force the correct domain at the same time.
[edited by: g1smd at 5:05 pm (utc) on Aug. 19, 2007]
RewriteCond %{REQUEST_URI} ^$
RewriteRule ^$ /info/about.php [L]
Maybe this would be better:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\ HTTP/
RewriteRule .* /info/about.php [L]
or this:
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /info/about.php [L]
or this:
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /info/about.php [L]
Darn typos and unclear thinking.
[edited by: g1smd at 9:46 pm (utc) on Aug. 20, 2007]
RewriteRule ^$ /info/about.php [L]
As for your root index file, it doesn't matter what you put into it, or even if it exists at all -- Because of the rewrite, the root index page's URL is now served with content from the file /info/about.php
Therefore, the file that used to correspond to example.com/ is no longer reachable using HTTP.
Jim
The root URL of the domain is the most important URL of your site. It should directly return content, but it does not matter where in the server file-system that content comes from.
It is bad form for the root URL to issue an external redirect to an internal URL of the site.
There is no problem for an external root URL request to be rewritten so that the content silently comes from some other file on the server.
The redirect from /info/about.php to "/" is to prevent Duplicate Content issues.