Forum Moderators: phranque

Message Too Old, No Replies

Encapsulated php script

         

Marfola

5:30 pm on Feb 12, 2009 (gmt 0)

10+ Year Member



I’m considering moving my 301 redirects from php (typo3) to an encapsulated redirect in a php script called by htaccess. (http://sebastians-pamphlets.com/the-anatomy-of-http-redirects-301-302-307/#how-to-implement-ss-redirect)

My .htaccess would read:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule (.*) do-redirects.php

do-redirects.php would check the URL with the REQUEST_URI and return a 301 redirect to the canonical and final URL if it exists, 404 otherwise.

Has anyone used this technique? Are there any pitfulls?


BTW: Can anyone recommend an alternative header tool to Websniffer? Someone recently suggested that Gooblebot might not like things Websniffer doesn’t mind.

g1smd

8:28 pm on Feb 12, 2009 (gmt 0)

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



Your rewrite would respond to a request for /robots.txt. The script would issue a redirect to what URL in that case?

What does a searchengine do when it sees the URL /robots.txt redirects elsewhere?

This and many other similar questions (images, CSS, JS, etc) need to be considered before you start writing any code.

Marfola

9:24 am on Feb 13, 2009 (gmt 0)

10+ Year Member



My script would only manage the non-www redirect in order to be sure to make a single redirect to the final www URL.
All www URLs would not be include in my script.

[edited by: Marfola at 9:24 am (utc) on Feb. 13, 2009]

jdMorgan

1:46 pm on Feb 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to exclude the "do-redirects.php" URL-path from being rewritten to itself in .htaccess, and from being redirected by the script itself; Otherwise, your rule will loop.

Jim

Marfola

7:13 pm on Feb 13, 2009 (gmt 0)

10+ Year Member



thanks for the advice.