Forum Moderators: coopster

Message Too Old, No Replies

custom php error pages tip

404, 301 redirect, etc

         

jamie

7:25 am on Dec 30, 2003 (gmt 0)

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



hi all,

this certainly isn't my code ;-) but i found the following article VERY useful:

custom error pages with php [onlamp.com]

delivering a 404 is fairly standard stuff, but it also describes a VERY easy way to deliver 301 redirects without any .htaccess and mod_rewrite voodoo.

i was just faced with the prospect of redirecting 150 pages from one domain to a new one, and i had the 301 redirect set up within 30 minutes, with no need for any mod_rewrite regex at all! (all checked with the server header checker on this site.... - all valid!)

hope this helps some people who are still rather confused by mod_rewrite ;-)

mogwai

2:46 pm on Dec 30, 2003 (gmt 0)

10+ Year Member



"hope this helps some people who are still rather confused by mod_rewrite ;-)"

Yes, it does :)

Good find, the article highlights some very interesting possibilities.

jatar_k

8:11 pm on Dec 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



true it is useful but it could be as simple as this in your apache conf or htaccess

Redirect Permanent /somedir/ http://www.mysite.com/newdir/

it took me longer to find the url than to type it

[httpd.apache.org...]

jamie

8:24 pm on Dec 30, 2003 (gmt 0)

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



hi jatar_k

yes, but then my htaccess ends up longer than my arm ;-)

and if i get the syntax wrong it causes the whole site to go offline.

i agree that that is rare, but it has happened... and the pressure is definitely off if i just have to edit a simple array in errors.php

jatar_k

8:29 pm on Dec 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



true, redirects can also be done by directory or even the whole site with one line. Though if every page is individually located in the root or you don't have dedicated servers then it can be helpful.

jamie

10:17 pm on Dec 30, 2003 (gmt 0)

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



hi jatar_k,

we do actually have our own dedicated server!

the problem was, that when we started we had combined our spanish pages with our english pages under the .com domain. using _i and _e to differentiate between them.

so i needed some sort of mod_rewrite regex to find all files which ended in _e.htm in the docroot and in various subfolders (not all) and redirect them to our new .es domain.

i tried and failed for about 2 rather frustrating hours before realising i had bookmarked that tutorial a while ago. :)

i know andreas or jdM would have magicked all that in a couple of hard to read lines ;-)