Forum Moderators: phranque

Message Too Old, No Replies

Is my 301 good for search engines?

         

tito

4:08 pm on Aug 19, 2007 (gmt 0)

10+ Year Member



Hello,

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

g1smd

4:44 pm on Aug 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Usually using .htaccess is better, as it doesn't rely on any PHP scripting having to work. It operates at a higher level, before anything is passed to the back end.

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]

tito

5:04 pm on Aug 19, 2007 (gmt 0)

10+ Year Member



Thank so much g1smd!

I will go with htaccess as you've explained.

Best,
tito

g1smd

5:08 pm on Aug 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The code above is untested. There may be a typo in it somewhere.

Be aware that the forum software here, breaks the ¦ character.

You need to replace each ¦ with the real pipe character on your keyboard.

tito

5:32 pm on Aug 19, 2007 (gmt 0)

10+ Year Member



Ok, I will make experiments, anyway your indications are much more than I did expect for. I appeciate.
I know abt the broken pipes, I spend my nights reading webmasterworld.

Thanks so much,
tito

g1smd

5:43 pm on Aug 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The first five blocks of code (out of six) were lifted from a working server and a job I was working on at that moment; just had to edit those to "example" and add one more block.

tito

11:29 pm on Aug 19, 2007 (gmt 0)

10+ Year Member



Thanks g1smd, I'm going to test the whole thing tomorrow night, I will let you know.

Thanks so smuch,
tito

g1smd

12:15 am on Aug 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In those final two lines I am not sure that ^$ is the best thing to use. Something else might be better.

I have never had to do a rewrite just for "/" so I might have guessed the wrong syntax at that point.

tito

8:52 pm on Aug 20, 2007 (gmt 0)

10+ Year Member



I'm testing it, but if I type in the browser the domain name nothing happens, it just get displayed the web root index page and I'm not redirected to /info/about.php.
Instead if I type on the browser www.domain.eu/info/about.php I am taken to the web root index page.

I'm trying to figure out why...

g1smd

8:58 pm on Aug 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This bit needs some modification:

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]

tito

9:10 pm on Aug 20, 2007 (gmt 0)

10+ Year Member



still the same behaviour but with Internal Server Error..

tito

9:31 pm on Aug 20, 2007 (gmt 0)

10+ Year Member



RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /info/about.php [L]

Yes, it's working!

Please one more question:
what should I place into web root index page?
some content, leave it empty, or can I just take away index web root page?

jdMorgan

9:40 pm on Aug 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should be able to replace that with the single line:

RewriteRule ^$ /info/about.php [L]

It is possible that you had problems because you were not completely flushing your browser cache between tests. Therefore, your browser was serving stale results from its cache, instead of accessing your server (a check of the server access logs will confirm this). Caches can cause confusing results if not accounted for...

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

tito

9:43 pm on Aug 20, 2007 (gmt 0)

10+ Year Member



clearly understood,
Thanks so much g1smd and Jim, I really appreciate, there's not places like webmasterworld.

Best,
tito

g1smd

9:48 pm on Aug 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For the want of a single "/", my original code would have worked.

I wasn't thinking 100% clearly on the original post.
Thanks to jdMorgan for the correction and addition.

tito

9:53 pm on Aug 20, 2007 (gmt 0)

10+ Year Member



I see, my fault I did not flush the browser cache, sorry.
Thanks so much g1smd for your great support.

Best,
tito

g1smd

9:55 pm on Aug 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For the record, Google indexes URLs that return content with a "200 OK" status and does not index URLs that return a "301 Moved" status code.

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.