中文版
Home Webmaster Smarter Online Dating Smarter Web Design Blog Links

Home > Blog > Programming

Wordpress Plugin: WP-DBManager

NetSmarter @ 2009-10-19 10:06  (Programming)

I just found a very useful Wordpress plugin: WP-DBManager.

This plugin manages your Wordpress database. Allows you to optimize database, repair database, backup database, restore database, delete backup database , drop/empty tables and run selected queries. Supports automatic scheduling of backing up and optimizing of database.

Here is the link.

Category: Programming



How to Install a CPAN module

NetSmarter @ 2009-04-08 06:19  (Programming)

To install the modules on a *nix system, type:

perl -MCPAN -e "install XML::Parser"
perl -MCPAN -e "install XML::RSS"

Category: Programming



How to Redirect Website Visitors To an Other Page/Site?

NetSmarter @ 2009-03-31 01:21  (Programming)

Method 1 - .htaccess 301 Redirect

The smoothest way to redirect your visitors is to use an .htaccess redirect. This has no delay since before a page is served to the browser the server checks first for an .htaccess file... if it sees this the old page never loads, instead visitors are sent directly to the new page.

These are a few .htaccess redirect codes that I've used that might come in handy for you. This is not a complete list by any means, but it took me ages to find how to do these so I'll save you the hassle and list them here. Oh, and please don't email me with questions about how these work, like I said, I found these with the help of others.. I have no idea in the slightest how to write this stuff and take no credit (or responsibility) for how they work.

If you're more technically minded than I am and want the information straight from the source, check the Apache Tutorial: .htaccess files for more detailed info.

Important notes about htaccess redirection

  1. Always be sure to upload .htaccess files in ascii mode, sending it up as binary will break it (and usually make your server very, very unhappy.)
  2. .htaccess does not work if you're on a windows server.
  3. Make sure you triple check your changes. Clear your cache and look, test the server headers to make sure you see a 301 (that means its permanent) not a 302 (temporary) unless you are absolutely sure you really mean temporary.
  4. Since some operating systems don't allow you to make a file without something before the "." you may need to save it as something.htaccess, some may even have to save it as htaccess.txt and change it once you've uploaded it.
  5. Make sure your ftp program will show .htaccess files (FileZilla does and is free) It is a bit hard to edit something you can't see ;)
  6. Double check that you're not overwriting an old one (some servers already place one there for your custom 404 pages etc.)
  7. Make sure you replace example.com with your own sites URL ;-)

301 Redirect Examples

To Move a single page

Quick, easy and seamless for your visitors.

To Move an entire site

This will catch any traffic on your old site and redirect it to your index page on your new server. If you want to redirect each page to its new spot, this isn't the one for you.

Changed file extension?

This example is perfect if you've decided to switch to .php from .html pages. It will look for any .html page and redirect it to .php (ie http://www.example.com/yourpage.html and redirect it to http://www.example.com/yourpage.php). Now, be careful with this, it does mean any html page. I did this on one of my sites and had totally forgotten I had an iframe with .html content on some pages... I didn't notice for weeks that it was broken :S.
So learn from my mistake ;-) check, double check, then check again.

Redirect www to non www version of site

It's best to stick with either always using www.example.com or just example.com. Allowing both can confuse the search engines. So here's how to force your site to always show the non-www version. (Search for "canonical url errors" in your favorite search engine for more info.)

Note: If you do use either of the next 2 codes below, and use a secure server (ie. https:) be sure to check that it doesn't redirect the secure to the insecure version. I'm pretty sure this will do that and that isn't something you want!

Redirect non-www to www

Same as above except in the reverse, this one forces the www. into your url.

Redirect example.com/index.php to example.com/

Another snippet that I've heard is a good idea to make sure search engines don't give you a duplicate content penalty, this will also redirect example.com/folder/index.php to example.com/folder/.

I might add more later as I need them, for now those are the one's I use on a few different sites I run. Remember, I can't stress enough to test, test and re-test anything you do to your .htaccess file.

Method 2 - Meta Redirect

I'd really advise against redirecting this way! Most search engine are having difficulties with this one (and spammers have been using this in very bad ways) and it might get your page in a heap of trouble! Some browsers also don't read it properly so your would-be visitors may get stranded. Seriously, it really isn't advisable to use this anymore but if you insist on trying it, here it is.

<meta http-equiv="refresh" content="10; url=http://example.com/">

Content="10; tells the browser to wait 10 seconds before transfer, choose however long you would like, you can even choose 0 to give a smoother transition.

Final Notes

I can't stress enough how important it is to test your server's response headers any time you make a change to your .htaccess file! If you use Firefox the LiveHTTPHeaders extensions is the best I've ever found. That will tell if you're sending a 301 (permanent redirect), 302 (temporary redirect, not what you want probably!) or 200 which means page found, as well as a ton of other info.

Category: Programming



WordPress XML-RPC Remote Posting Problem

NetSmarter @ 2008-12-23 01:29  (Programming)

I was trying to use Windows Writer to post to a WordPress blog. However, I got an error message saying "xmlrpc.php 403 forbidden". After some research, I finally found the solution.

Just add the following lines to the .htaccess file:

<Files xmlrpc.php>
SecFilterInheritance Off
</Files>

Category: Programming



Installing a CPAN Perl module from a non-root account

NetSmarter @ 2008-07-12 01:24  (Programming)

Source: http://www.soe.ucsc.edu/~you/notes/perl-module-install.html

Problem: you do not have root permission but want to install a Perl module in a local directory and the module can be located from your scripts.

CPAN Perl modules

Refer to Installing CPAN Modules and this section in the CPAN FAQ.

Download the Perl module

Find the Perl module you want. Google or the CPAN Search Site are usually good ways to find the module. Download a copy of the entire package (usually a .tar.gz, not the individual .pm "Perl module" file) into a download directory. I usually keep a directory named ~/downloads.

Install the Perl module into your ~/lib directory

Unpack the CPAN Perl module:

cd ~/src
tar -zxvf ~/downloads/Statistics-Descriptive-2.6.tar.gz

(The conventional installation method is:

cd ~/src/Statistics-Descriptive-2.6
perl Makefile.PL
make
make test
make install

)

But specify the installation into ~/lib/perl5 instead:

cd ~/src/Statistics-Descriptive-2.6
perl Makefile.PL PREFIX=~/lib/perl5
make
make test
make install

Installing /home/you/lib/perl5/site_perl/5.8.2/Statistics/Descriptive.pm
Writing /home/you/lib/perl5/site_perl/5.8.2/cygwin-thread-multi-64int/auto/Statistics/Descriptive/.packlist
Appending installation info to /home/you/lib/perl5/5.8.2/cygwin-thread-multi-64int/perllocal.pod

Change your Perl scripts so that they can find the Perl module that you have installed locally

See this section in the CPAN FAQ.

I prefer the first method that is mentioned, which is to set the environment variable. This is easy to do in a login script.

setenv PERL5LIB /path/to/module sets the environment variable PERL5LIB.

With Bash:

 export PERL5LIB=~/lib/perl5/site_perl

Remove the Perl module

Just remove the appropriate files from ~/lib/perl5. Or use the  ExtUtils package to help you remove the files.

Category: Programming



View All Posts >>

Categories:

Most Recent Posts:


Google Reader or Homepage
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online

Add to Technorati Favorites!

 

Home Webmaster Smarter Online Dating Smarter Web Design Blog Links

© Copyright NetSmarter.com. All rights reserved.