Skip navigation

Category Archives: SEO

GeoIP Apache API

Requirements
In order to run this API, you need the following installed:

Download
Downloads are available for Apache 1.3.x and Apache 2.x.

Install
See the INSTALL file included with the mod_geoip API download for detailed instructions.

Usage
mod_geoip looks up the IP address of the client end user. If you need to input the IP address instead of simply using the client IP address, you will need to use another one of our APIs.

For the country database, mod_geoip sets two environment variables, GEOIP_COUNTRY_CODE and GEOIP_COUNTRY_NAME. For other databases, see the README file included with the mod_geoip API.

It also sets two entries in Apache’s notes table with the same names as above.

For more documentation, see the README file included with the mod_geoip API download.

Examples
Redirection with mod_geoip and mod_rewrite
Below are examples of how to perform redirection based on country with mod_geoip and mod_rewrite. This configuration should be added to your Apache httpd.conf or .htaccess file.

GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat

# Redirect one country
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://www.canada.com$1 [L]

# Redirect multiple countries to a single page
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CA|US|MX)$
RewriteRule ^(.*)$ http://www.northamerica.com$1 [L]

This example redirects all pages on your site to a corresponding page on www.canada.com. For more details on how to use Apache’s redirection features, see the Apache 1.3 URL Rewriting Guide.

Blocking unwanted countries
The following Apache configuration directives uses GeoIP Country to block traffic from China and Russia:

GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat

SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
# ... place more countries here

Deny from env=BlockCountry

# Optional - use if you want to allow a specific IP address from the country you denied
# (See http://httpd.apache.org/docs/1.3/mod/mod_access.html for more details)
Allow from 10.1.2.3

Allowing only specified countries
The following Apache configuration directives uses GeoIP Country to only allow traffic from US, Canada, and Mexico.

GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat

SetEnvIf GEOIP_COUNTRY_CODE US AllowCountry
SetEnvIf GEOIP_COUNTRY_CODE CA AllowCountry
SetEnvIf GEOIP_COUNTRY_CODE MX AllowCountry
# ... place more countries here

Deny from all
Allow from env=AllowCountry

# Optional - use if you want to allow a specific IP address from the country you denied
# (See http://httpd.apache.org/docs/1.3/mod/mod_access.html for more details)
Allow from 10.1.2.3

Some Good Official Tutorials

Sample .htaccess file from htaccess Google Group

Read More »

  1. Install Apache 2.
  2. Install mod_fastcgi.
  3. Add to Apache’s httpd.conf:
     AddHandler fastcgi-script rb
     ScriptAlias / /usr/local/www/data/dispatch.rb/
  4. In dispatch.rb:
     #!ruby
     #!/usr/local/bin/ruby
     require 'rubygems'
     require 'camping/fastcgi'
     Camping::Models::Base.establish_connection :adapter => 'sqlite3',
       :database => "/tmp/camping.db"
     Camping::FastCGI.serve("/usr/local/data/examples/")

Serving One File

The above setup will serve a whole directory, just like TheCampingServer. If you only want to serve one app (at the root) change the last line in dispatch.rb to point to a single file.

 #!ruby
 Camping::FastCGI.serve("/usr/local/data/examples/blog.rb")

Mounting at a Subdirectory

You can certainly use ScriptAlias to attach the Camping app to a subdirectory, rather than root. If you are using URL() and R() in your code, the paths will change accordingly.

 ScriptAlias /myapp /usr/local/www/data/dispatch.rb/

FastCGI .htaccess

This is a basic FastCGI .htaccess file. The last line is the most important.

AddHandler fastcgi-script .fcgi 

Options +FollowSymLinks +ExecCGI  

RewriteEngine On  
RewriteRule ^$ index.html [QSA] 
RewriteRule ^([^.]+)$ $1.html [QSA] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]

dispatch.fcgi

* Make sure your dispatch.fcgi is marked as executable! Run “chmod 755 dispatch.fcgi” if you’re not sure. * The second part of GEM_PATH should be your host’s installed gems location, the example below is taken from Dreamhost.

#!/usr/bin/ruby

ENV['GEM_PATH'] = '/path/to/my/gems:/usr/lib/ruby/gems/1.8'
ENV['GEM_HOME'] = '/path/to/my/gems'

Dir.chdir '/path/to/my_app'

require 'my_app'
MyApp.create

class ApacheFixer
  def initialize(app); @app = app; end

  def call(env)
    env['SCRIPT_NAME'] = '/'
    env['PATH_INFO'] = env['REQUEST_URI'][0..(env["REQUEST_URI"].index("?")||0)-1]
    @app.call(env)
  end
end

Rack::Handler::FastCGI.run ApacheFixer.new(MyApp)

Using CGI

If you’re having issues with FastCGI, try to get it working with CGI first. To do this, change the examples above:

  • In dispatch.fcgi, change “Rack::Handler::FastCGI” to “Rack::Handler::CGI”.
  • Rename dispatch.fcgi to dispatch.cgi.
  • Update the last line of .htaccess to point to dispatch.cgi instead of dispatch.fcgi.

Notes for Dreamhost

  • If you’re having trouble with timeouts, try getting this to work for CGI first. If CGI works, then FastCGI should work, and Dreamhost is just being stupid. Change it back to use FastCGI, and come back later. This worked for me a couple times, and I place the blame on Dreamhost.
  • Set up your own gem path that you can install to and edit manually.
  • If you followed the Dreamhost guide to making your own gem path, your gem path would be /home/username/.gems.
  • If you’re trying to install gems remotely, Dreamhost will probably kill the process before it finishes. For me, using the ‘nice’ command didn’t help. Get the gem files, scp them to your server, and install them locally (i.e. “gem install activesupport-2.1.0.gem”). This means installing dependencies in turn (activesupport, markaby, and metaid before camping).


Wordtracker helps website owners and search engine marketers identify keywords and phrases that are relevant to their or their client’s business and most likely to be used as queries by search engine visitors.

Marketers can also determine how many competing sites are using those keywords and can identify the phrases that have the greatest traffic potential.

Wordtracker periodically compiles a database of over 330 million search terms which is updated on a weekly basis. All search terms are collected from the major metacrawlers – Dogpile and Metacrawler.

.htaccess

109 searches (top 100 only)
Searches Keyword
109 total searches
34 .htaccess
6 .htaccess file
6 .htaccess generator
4 .htaccess file not working
4 .htaccess file showing up that i didn’t put there
4 .htaccess ignores javascript redirects
4 .htaccess redirect
4 .htaccess rewriteengine off
3 .htaccess 404 redirect
3 .htaccess php_flag
3 .htaccess tutorial
3 creating a .htaccess file
3 expires .htaccess
3 what is .htaccess
3 what is the .htaccess file
2 .htaccess hide index
2 .htaccess linux
2 .htaccess password generator
2 .htaccess php_value not allowed here
2 .htaccess rewrite
2 .htaccess secure directories
2 .htaccess to redirect certain links
2 .htaccess to redirect certain outgoing links
2 joomla file .htaccess
2 linux .htaccess
2 use .htaccess to change url

Wordtracker was established by Andy Mindel and Mike Mindel in 1997 to answer a fundamental question in the search engine industry:

“What are people searching for on the Web?”

Turn Vim into a bash IDE

By Joe ‘Zonker’ Brockmeier on June 11, 2007 (9:01:00 PM)

By itself, Vim is one of the best editors for shell scripting. With a little tweaking, however, you can turn Vim into a full-fledged IDE for writing scripts. You could do it yourself, or you can just install Fritz Mehner’s Bash Support plugin.

To install Bash Support, download the zip archive, copy it to your ~/.vim directory, and unzip the archive. You’ll also want to edit your ~/.vimrc to include a few personal details; open the file and add these three lines:

let g:BASH_AuthorName   = 'Your Name'
let g:BASH_Email        = 'my@email.com'
let g:BASH_Company      = 'Company Name'

These variables will be used to fill in some headers for your projects, as we’ll see below.

The Bash Support plugin works in the Vim GUI (gVim) and text mode Vim. It’s a little easier to use in the GUI, and Bash Support doesn’t implement most of its menu functions in Vim’s text mode, so you might want to stick with gVim when scripting.

When Bash Support is installed, gVim will include a new menu, appropriately titled Bash. This puts all of the Bash Support functions right at your fingertips (or mouse button, if you prefer). Let’s walk through some of the features, and see how Bash Support can make Bash scripting a breeze.

Header and comments

If you believe in using extensive comments in your scripts, and I hope you are, you’ll really enjoy using Bash Support. Bash Support provides a number of functions that make it easy to add comments to your bash scripts and programs automatically or with just a mouse click or a few keystrokes.

When you start a non-trivial script that will be used and maintained by others, it’s a good idea to include a header with basic information — the name of the script, usage, description, notes, author information, copyright, and any other info that might be useful to the next person who has to maintain the script. Bash Support makes it a breeze to provide this information. Go to Bash -> Comments -> File Header, and gVim will insert a header like this in your script:

#!/bin/bash
#===============================================================================
#
#          FILE:  test.sh
#
#         USAGE:  ./test.sh
#
#   DESCRIPTION:
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  Joe Brockmeier, jzb@zonker.net
#       COMPANY:  Dissociated Press
#       VERSION:  1.0
#       CREATED:  05/25/2007 10:31:01 PM MDT
#      REVISION:  ---
#===============================================================================

You’ll need to fill in some of the information, but Bash Support grabs the author, company name, and email address from your ~/.vimrc, and fills in the file name and created date automatically. To make life even easier, if you start Vim or gVim with a new file that ends with an .sh extension, it will insert the header automatically.

As you’re writing your script, you might want to add comment blocks for your functions as well. To do this, go to Bash -> Comment -> Function Description to insert a block of text like this:

#===  FUNCTION  ================================================================
#          NAME:
#   DESCRIPTION:
#    PARAMETERS:
#       RETURNS:
#===============================================================================

Just fill in the relevant information and carry on coding.

The Comment menu allows you to insert other types of comments, insert the current date and time, and turn selected code into a comment, and vice versa.

GDB Documentation

Printed Manuals

The GNU Press has printed versions of most manuals, including Debugging with GDB available.

Online GDB manuals

Documentation generated from the current sources are available online:

GDB User Manual (gziped PDF)
Describes how to use GDB.
Translations are also available:

GDB Internals Manual (gziped PDF)
Technical details of the internals of GDB.

The documentation is also available for download in a number of different formats including (HTML, DVI, PS and PDF).

Versions of the documentation generated from the last release and most recent branch are also available.

Reference Material

Additional documentation includes:

GDB interfaces and standards

Object files and debugging formats

Architecture manuals

Also see Chip Documentation from GCC.

[bugs] [committee] [contributing] [current cvs] [documentation] [downlo

What is GNU?

The GNU Project was launched in 1984 to develop a complete Unix-like operating system which is free software: the GNU system.

GNU’s kernel wasn’t finished, so GNU is used with the kernel Linux. The combination of GNU and Linux is the GNU/Linux operating system, now used by millions. (Sometimes this combination is incorrectly called Linux.)

There are many variants or “distributions” of GNU/Linux. We recommend the GNU/Linux distributions that are 100% free software; in other words, entirely freedom-respecting.

The name “GNU” is a recursive acronym for “GNU’s Not Unix”; it is pronounced g-noo, as one syllable with no vowel sound between the g and the n.

<!–

Get started!

Get started today, download gNewSense – a complete free software distribution of GNU/Linux for your desktop computer.

Download now or download with KDE.

–>

What is Free Software?

Free software” is a matter of liberty, not price. To understand the concept, you should think of “free” as in “free speech”, not as in “free beer”.

Free software is a matter of the users’ freedom to run, copy, distribute, study, change and improve the software. More precisely, it refers to four kinds of freedom, for the users of the software:

  • The freedom to run the program, for any purpose (freedom 0).
  • The freedom to study how the program works, and adapt it to your needs (freedom 1). Access to the source code is a precondition for this.
  • The freedom to redistribute copies so you can help your neighbor (freedom 2).
  • The freedom to improve the program, and release your improvements to the public, so that the whole community benefits (freedom 3). Access to the source code is a precondition for this.

.htaccess Magic!

By Katherine Nolan
Expert Author
Article Date: 2003-04-16

If your site is hosted on a Unix or Linux server which runs Apache, you may already be familiar with your .htaccess file.

We referred to it in an earlier tutorial on Creating Custom Error Messages, where we showed how you can configure it to instruct the browser to display custom error messages rather than the dull and unhelpful generic ones.

But that is far from the whole story! In this article we will look at some of the other things that this powerful little file can do. In part two we have 7 Magic Tricks that you can perform with .htaccess, but first let’s have a look at the file itself.

What is the .htaccess file?

The .htaccess file is a  text file which resides in your main site directory and/or in any subdirectory of your main directory. There can be just one, there can be a separate one in each directory or you may find or create one just in a specific directory.

Any commands in a .htaccess file will affect both the directory it is in and any subdirectories of that directory. Thus if you have just one, in your main directory, it will affect your whole site. If you place one in a subdirectory it will affect all the contents of that directory.

Some Important Points

Windows does not use the .htaccess system. I believe there are ways of doing the things .htaccess does on Windows servers but that is a story for another day and I am afraid I will not be telling it  – it just isn’t as simple or as elegant as the way Apache manages things in my humble opinion! So unless you are on a Linux/Unix server, this article is no good to you. Sorry.

A warning you will commonly see is that changing the .htaccess file on a server that has FrontPage extensions installed will at best not work and at worst make a complete mess of your extensions. I have to say that this has not been my experience and I have done a fair bit of messing with .htaccess files on FrontPage sites, including using .htaccess for authentication. However do any of these things at your own risk – I cannot be responsible for any harm they might cause.

Your host may not support alteration of the .htaccess file; either contact them first and ask before you make changes or proceed with caution and be sure you have a backup of the original file in case of problems.

Oh! And none of the ‘Magic Tricks’ described in this article are either magic or tricks. They just seem that way!

Working With Your .htaccess File

Sometimes the first problem is finding it! When you FTP to your site the .htaccess file is generally the first one displayed in a directory if it exists.

screenshotSome servers are configured to hide files whose names begin with a period. Your FTP client allows you to chose to display these files. In WS_FTP you can do this by entering -la or -al as indicated in the image on the left and then clicking Refresh. Other clients may use a different method – check the help files in yours.

Editing should be done in a text editor, such as NotePad. You should not edit .htaccess files in editors such as FrontPage. The best thing to do is download a copy of your .htaccess file to your computer, edit it, and upload again, remembering to save a copy of the original in case of errors.

If you do not already have a .htaccess file you can create one in NotePad, it is just a simple text file. However when saving it to the server you may need to rename it from .htaccess.txt to just .htaccess. The two are NOT the same. In fact .htaccess is an extension – to a file with no name!

It is very important when entering commands in your file that each is entered on a new line and that the lines do not wrap. If you find that when you paste any of the commands in this article into your file that the lines are not breaking or are wrapping you will need to correct this.

You must upload and download your .htaccess file in ASCII mode, not BINARY.

So, What about the Magic Tricks? Read on!

Well, first another boring bit! To prevent people from being able to see the contents of your .htaccess file, you need to place the following code in the file:

<Files .htaccess> order allow,deny deny from all </Files>

Be sure to format that just as it is above, with each line on a new line as shown. There is every likelihood that your existing .htaccess file, if you have one, includes those lines already.

Magic Trick No. 1: Redirect to Files or Directories

You have just finished a major overhaul on your site, which unfortunately means you have renamed many pages that have already been indexed by search engines, and quite possibly linked to or bookmarked by users. You could use a redirect meta tag in the head of the old pages to bring users to the new ones, but some search engines may not follow the redirect and others frown upon it.

.htaccess leaps to the rescue!

Enter this line in your .htaccess file:

Redirect permanent /oldfile.html http://www.domain.com/filename.html

You can repeat that line for each file you need to redirect. Remember to include the directory name if the file is in a directory other than the root directory:

Redirect permanent /olddirectory/oldfile.html http://www.domain.com/newdirectory/newfile.html

If you have just renamed a directory you can use just the directory name:

Redirect permanent /olddirectory http://www.domain.com/newdirectory

(Note:The above commands should each be on a single line, they may be wrapping here but make sure they are on a single line when you copy them into your file.)

This has the added advantage of preventing the increasing problem on the Internet, as people change their sites, of ‘link rot’. Now people who have linked to pages on your site will still have functioning links, even if the pages have changed location.

Magic Trick No. 2: Change the Default Directory Page

In most cases the default directory page is index.htm or index.html. Many servers allow a range of pages called index, with a variety of extensions, to be the default page.

Suppose though (for reasons of your own) you wish a page called honeybee.html or margarine.html to be a directory home page?

No problem. Just put the following line in your .htaccess file for that directory:

Directory Index honeybee.html

You can also use this command to specify alternatives. If the first filename listed does not exist the server will look for the next and so on. So you might have:

Directory Index index.html index.htm honeybee.html margarine.html

(Again, the above should all be on a single line)

Magic Trick No. 3: Allow/Prevent Directory Browsing

Most servers are configured so that directory browsing is not allowed, that is if people enter the URL to a directory that does not contain an index file they will not see the contents of the directory but will instead get an error message. If your site is not configured this way you can prevent directory browsing by adding this simple line to your .htaccess file:

IndexIgnore */*

But there may be times when you want to allow browsing, perhaps to allow access to files for downloading or for whatever reason, on a server configured not to allow it. You can override the servers settings with this line:

Options +Indexes

Easy!

Magic Trick No. 4: Allow SSI in .html files

Most servers will only parse files ending in .shtml for Server Side Includes. You may not wish to use this extension, or you may wish to retain the .htm or .html extension used by files prior to your changing the site and using SSI for the first time.

Add the following to your .htaccess file:

AddType text/html .html AddHandler server-parsed .html AddHandler server-parsed .htm

You can add both extensions or just one.

Remember though  that files which must be parsed by the server before being displayed will load more slowly that standard pages. If you change things as above, the server will parse all .html and .htm pages, even those that do not contain any includes. This can significantly, and unnecessarily, slow down the loading of pages without includes.

Magic Trick No 5: Keep Unwanted Users Out

You can ban users by IP address or even ban an entire range of IP addresses. This is pretty drastic action, but if you don’t want them, it can be done very easily.

Add the following lines:

order allow,deny deny from 123.456.78.90 deny from 123.456.78 deny from .aol.com allow from all

The second line bans the IP address 123.456.78.90, the third line bans everyone in the range 123.456.78.1 to 123.456.78.999 and so is much more drastic. The fourth line bans everyone from AOL. A somewhat excessive display of power perhaps!

One thing to bear in mind here it that banned users will get a 403 error -  “You do not have permission to access this site”, which is fine unless you have configured a custom error for this page which in fact appears to let them in. So bear that in mind and if you are banning users for whatever reason make sure your 403 error message is a dead end.

Magic Trick No. 6: Prevent Linking to Your Images

The greatest and most irritating bandwidth leech is having someone link to images on your site. You can foil such thieves very easily with .htaccess. Copy the following into your .htaccess file:

RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www.)?domain.com/.*$ [NC] RewriteRule .(gif|jpg)$ – [F]

You don’t need to understand any of that! Just change ‘domain.com’ to the name of your domain.

(Again each command should be on a single line. There are 4 lines above, each starting with ‘Rewrite’)

If you want to really let them know they have been rumbled why not make an image like the one below (or take this one if you like)

stolen

call it stealing.gif, save it to your images file and add the following line after the code abov

RewriteRule .(gif|jpg)$ http://www.domainname.com/images/stealing.gif [R,L]

(The above command should be on a single line)

Magic Trick No 7: Stop the Email Collectors

While you positively want to encourage robot visitors from the search engines, there are other less benevolent robots you would prefer stayed away. Chief among these are those nasty ‘bots that crawl around the web sucking email addresses from web pages and adding them to spam mail lists.

RewriteCond %{HTTP_USER_AGENT} Wget [OR] RewriteCond %{HTTP_USER_AGENT} CherryPickerSE [OR] RewriteCond %{HTTP_USER_AGENT} CherryPickerElite [OR] RewriteCond %{HTTP_USER_AGENT} EmailCollector [OR] RewriteCond %{HTTP_USER_AGENT} EmailSiphon [OR] RewriteCond %{HTTP_USER_AGENT} EmailWolf [OR] RewriteCond %{HTTP_USER_AGENT} ExtractorPro RewriteRule ^.*$ X.html [L]

Note that at the end of each line for a named robot there appears an ‘[OR]‘ – don’t forget to include that if you add any others to this list.

This is by no means foolproof. Many of these sniffers do not identify themselves and it is almost impossible to create an exhaustive list of those that do. It’s worth a try though if it even keeps some away. The above is as many as I could find.

….and Finally

There is one very important area of the .htaccess file’s use that we have not really mentioned and that is its use for user authentication. It is perfectly possible to configure your .htaccess files by hand to control access to directories on your site, but this is rarely necessary.

In most cases your host will provide a method to allow you to much more easily configure the file from your hosting control panel and there are a myriad of Perl scripts that will allow you to set up full user management systems by harnessing the power of .htaccess.

If you do want to go it alone there is a tutorial here that will get you there: http://www.apacheweek.com/features/userauth

If you are looking for scripts there a many here: http://www.hotscripts.com/Perl/Scripts_and_Programs/Password_Protection/

Two scripts that I have used and can recommend are:

1. Locked Area
The free version will be adequate for many situations, though both versions will give you control over access to one directory and its contents only.

http://www.locked-area.com/html/

2. Password Manager
Allows you very sophisticated control over access to multiple directories. Not cheap but very good value for money.

http://www.cgi-world.com/password_manager.html

Have fun!

Article reprinted with permission from Thomas Brunt’s OutFront, a Microsoft FrontPage learning community

http://www.outfront.net


About the Author:
Katherine Nolan
OutFront Moderator

.htaccess redirect

Editing the .htaccess file can make your website inaccessible if done incorrectly. Always make sure you have a back-up of the current version of the .htaccess file, to go back to a working version.

.htaccess is a file on Apache servers. It’s a very powerful tool, but often requires rather detailed technical knowledge to edit. Thankfully it’s not that difficult for the purpose of redirecting pages on server level.

Step 1: Check for existing .htaccess
First you need to find out whether you have a .htaccess file already. Start your FTP-program (make sure your program shows the .htaccess file), browse to the root of your domain and look for it (it’s usually on top of the list). If it’s there, download it. Make sure to make a back-up of the current file!

Step 2: Edit it to add redirects
Open the .htaccess file in a text editor and add the following lines to the file.

# Temporary redirects for affiliate links
Redirect 302 /[subdir]/[filename] http://example.com/?id=12345
Redirect 302 /[subdir]/[filename] http://example.com/?id=34567
# End of affiliate redirects

Now replace /[subdir]/[filename] with the right link, and replace http://example.com/?id=12345 with the address you want to send your visitors to when they click the link.

Make sure you use a temporary redirect. The status code 302 tells the other server that the page is redirected temporary, and that they should not update their addresses to the new address.

For example, for my e-junkie affiliate link this looks like this:

Redirect 302 /go/e-junkie.php http://www.e-junkie.com/?r=11261

Step 3: Save and upload
Upload and overwrite the old .htaccess file on the server.
Again make sure you have a back-up of the old version before you do this!

Step 4: Link to it.
That’s it, now use that link instead of the original link. It doesn’t even matter if there’s a file or not on the original location.

Again, use caution with this file. Make sure you have a copy of a working version and ftp-access to your server in case things go wrong. An error in the .htaccess file could effectively deny you access to the WordPress Admin interface. In which case you’ll have to replace the erroneous file with the back-up through FTP.

Follow

Get every new post delivered to your Inbox.