internetearnings.com

How to Redirect 404 Not Found Page Using .htaccess

Recently, I moving one of my website from WordPress CMS to normal static html. I found out that there are too many 404 not found errors.

One of the solutions is to redirect it to more meaningful page, especially the Homepage. Although some people may argue, the usefulness of the redirects. However, I prefer to do so on some of my websites.

To do this I need to edit “.htaccess” which located at the root folder of the particular website. If you are unable to see the file, make sure you allow to view hidden files since “.htaccess” is a hidden file. If it still not there, then create it.

The following procedure, guides on how to redirect.

  1. If you are using cPanel, log into front-end and click on “File Manager” application. Make sure you enable the hidden file viewers.
  2. Go to the root folder of the website & edit or create “.htaccess” file.
  3. Add the following code & replace YOURURL with the URL where you want the error 404 page redirected to.
  4. Click save & you are done.
ErrorDocument 404 http://YOURURL

How to Install Lighttpd & PHP on Dlink DNS-320

I just obtain my new D-link DNS-320 NAS Storage which supposed to replace my older DNS-323 that died recently. As before, I need to install Webserver Lighttpd & PHP. This guide assumed that you have installed Fonz fun_plug in your DNS-320. This guide should work on D-link DNS-325 as well.

I choose fonz fun_plug version 0.5 instead of version 0.7 as I am unable to get it working correctly.

This guides are divided into 3 main section namely download packages, install, configure & finishing up. I also include some optional guides.

Download

1. Download lighttpd packages

2. Download PHP packages

Install

1. Run PuTTY and log into DNS-320

2. Change directory to “/mnt/HD/HD_a2” & create “pkg” folder inside “ffp” folder. If you are copying from a Windows PC you may need to set permission to copy.

cd /mnt/HD/HD_a2
mkdir -p /ffp/pkg
chmod -R 0777 /ffp/pkg

3. Copy all packages downloaded above into the folder “/ffp/pkg

4. Update & install Lighttpd packages

funpkg -u /ffp/pkg/lighttpd-1.4.29-1.tgz
funpkg -i /ffp/pkg/openssl-0.9.8k-1.tgz

5. Install PHP packages

funpkg -i /ffp/pkg/php-5.2.17-3.tgz
funpkg -i /ffp/pkg/curl-7.23.0-1.tgz
funpkg -i /ffp/pkg/libiconv-1.12-3.tgz

Configure

1. Create all folders required by Lighttpd

mkdir -p /ffp/opt/srv/mysql
mkdir -p /ffp/opt/srv/www/pages
mkdir -p /ffp/opt/srv/www/logs
mkdir -p /ffp/opt/srv/tmp

2. Create a symbolic link

ln -s /ffp/opt/srv/ /srv

3. Symbolik link above will be lost when you restart your DNS-320. To make it permanent, edit “/ffp/etc/fun_plug.init” file. If you are editing it from a Windows PC you may need to set permission to edit.

chmod 0777 /ffp/etc/fun_plug.init

4. Open your favoutrite text editor (don’t use notepad or it will corrupt the files) and open “/ffp/etc/fun_plug.init” file. Add the following at the end.

ln -s /ffp/opt/srv/ /srv

5.  Copy Lighttpd & PHP configuration files

cp /ffp/etc/examples/lighttpd.conf-dns320 /ffp/etc/lighttpd.conf
cp /ffp/etc/examples/php.ini-wolfuli /ffp/etc/php.ini

6. Stating up Lighttpd webserver

chmod a+x /ffp/start/lighttpd.sh
chmod a+x /ffp/start/kickwebs_dns320.sh
sh /ffp/start/kickwebs_dns320.sh start
sh /ffp/start/lighttpd.sh start

Finishing up

1. Your Lighttpd with PHP support should be running by now. Root folder of the web server is located at “/ffp/opt/srv/www/pages“. Test it by create a file named “index.php” which contains the following.

<h1>This is normal HTML</h1>
But the <u>following table</u> is generated by PHP:
<?php
phpinfo();
?>

2. Open web browser and point it to “http://dns320-ip/“. Change “dns320-ip” to your DNS-320 IP address. You should see both notmal HTML & PHP generated output. Your DNS-320 admin page had move to “http://dns320-ip:81/”

Optional

1. For me, I would like to change Lighttpd port to “8080” & revert back admin page to port “80“. To do this, I need to edit “/ffp/etc/lighttpd.conf” file. If you are editing it from a Windows PC you may need to set permission to edit.

chmod 0777 /ffp/etc/lighttpd.conf

i. Find the following

server.port = 80

and change it to

server.port = 8080

ii. Find the following

$SERVER["socket"] == ":81" {

and change it to

$SERVER["socket"] == ":80" {

2. I also would like to enable directory listing. On the same “/ffp/etc/lighttpd.conf” file.

i. Find the following

#dir-listing.activate        = "enable"

and change it to

dir-listing.activate        = "enable"

3. To apply the changes, you have to restart Lighttpd.

sh /ffp/start/lighttpd.sh restart

4. By now, your web server serving port should change to “8080” and admin page port back to “80“. Test it on your web browser.