1 / 3
Caption Text
2 / 3
Caption Two
3 / 3
Caption Three margin testing

Sunday, August 8, 2010

What is the difference between "Chrome extensions" and Chrome web apps in the Chrome Web Store?

http://www.google.com/support/forum/p/Chrome/thread?tid=3fe8254037936fdb&hl=en

Extensions are designed to add extra functionality to the browser and are also designed to generally only work in chrome. The chrome Web Store will show web applications that can be run in any modern browser that supports some feature's such as html5. However there are some advantages to use there applications with chrome such as shortcuts placed in the browser and more functionality.

Friday, August 6, 2010

When site is “Under Construction”

http://www.askapache.com/htaccess/htaccess-for-webmasters.html

This lets google crawl, lets me access (1.1.1.1) without a password, and lets access from anyone WITH a password. It also allows for XHTML and CSS validation through w3.org

Article: Instruct Search Engines with a 503 Service Unavailabe header and Retry-After header while site is offline

AuthName "Under Development"
AuthUserFile /home/askapache.com/.htpasswd
AuthType basic
Require valid-user
Order Deny,Allow
Deny from all
Allow from 1.1.1.1 w3.org googlebot.com google.com google-analytics.com
Satisfy Any

Hide the Apache Version number and Server information

http://serversignature.com/Apache2-Turning-ServerSignature-off

By default many Apache installations tell the world what version of Apache you're running, what operating system/version you're running, and even what Apache Modules are installed on the server. Attackers can use this information to their advantage when performing an attack. It also sends the message that you have left most defaults alone.

The ServerSignature appears on the bottom of pages generated by apache such as 404 pages, directory listings, etc.

The ServerTokens directive is used to determine what Apache will put in the ServerHTTP response header. By setting it to Prod it sets the HTTP response header as follows:

 Server: Apache

To disable server signature, you will need to open your /etc/apache2/apache2.conf file,
and search for "ServerSignature" and press return. If you find it, edit it to:

ServerSignature Off
ServerTokens Prod


If you don't find it, just scroll to the end of the file and add these two lines.
Then, we need to reload apache configuration to put this new change in effect:

sudo /etc/init.d/apache2 reload

htaccess Tricks for Webmasters

http://www.askapache.com/htaccess/htaccess-for-webmasters.html

Apache For Webmasters is some of my favorite htaccess examples from some of my favorite .htaccess tutorials. These cut-and-paste ready htaccess code snippets are very useful for website and server administrators.

Apache Custom Error Messages

http://www.htmlcenter.com/blog/apache-custom-error-messages/

You log onto your shell and create a file called .htaccess in your document root. Let's assume that you want to display a custom error page for "File not found"-errors (code: 404).

Put the following code inside the .htaccess:


ErrorDocument 404 /path/to/error/document.html


Save it. Viola! It's all done.

You may also refer to a remote document:


ErrorDocument 404 http://errors.domain.com/404.php


The syntax is as follows:


ErrorDocument <3-digit-code> action


Can't get enough of them?

Successful Client Requests
200OK
201Created
202Accepted
203Non-Authorative Information
204 No Content
205Reset Content
206Partial Content
Client Request Redirected
300Multiple Choices
301Moved Permanently
302 Moved Temporarily
303See Other
304Not Modified
305 Use Proxy
Client Request Errors
400Bad Request
401 Authorization Required
402Payment Required (not used yet)
403Forbidden
404Not Found
405Method Not Allowed
406Not Acceptable (encoding)
407Proxy Authentication Required
408Request Timed Out
409 Conflicting Request
410Gone
411Content Length Required
412Precondition Failed
413Request Entity Too Long
414Request URI Too Long
415Unsupported Media Type
Server Errors
500 Internal Server Error
501Not Implemented
502Bad Gateway
503Service Unavailable
504Gateway Timeout
505HTTP Version Not Supported

Have fun!

Thursday, August 5, 2010

Apache mod_rewrite Introduction

http://httpd.apache.org/docs/2.2/rewrite/rewrite_intro.html#page-header
(I followed this guide to create my .htaccess, HL 20100805)


The Apache module mod_rewrite is a very powerful and sophisticated module which provides a way to do URL manipulations. With it, you can do nearly all types of URL rewriting that you may need.

Remember that many common URL-manipulation tasks don't require the full power and complexity of mod_rewrite. For simple tasks, see mod_alias and the documentation on mapping URLs to the filesystem.

Finally, before proceeding, be sure to configure the RewriteLog. Although this log file can give an overwhelming amount of information, it is indispensable in debugging problems with mod_rewriteconfiguration, since it will tell you exactly how each rule is processed.

top

Regular Expressions

mod_rewrite uses the Perl Compatible Regular Expression vocabulary. In this document, we do not attempt to provide a detailed reference to regular expressions. For that, we recommend the PCRE man pages, the Perl regular expression man page, and Mastering Regular Expressions, by Jeffrey Friedl.

Regex vocabulary

The following are the minimal building blocks you will need, in order to write regular expressions and RewriteRules.

Character Meaning Example
. Matches any single character c.t will match cat, cot, cut, etc.
+ Repeats the previous match one or more times a+ matches a, aa, aaa, etc
* Repeats the previous match zero or more times. a* matches all the same things a+ matches, but will also match an empty string.
? Makes the match optional. colou?r will match color and colour.
^ Called an anchor, matches the beginning of the string ^a matches a string that begins with a
$ The other anchor, this matches the end of the string. a$ matches a string that ends with a.
( ) Groups several characters into a single unit, and captures a match for use in a backreference. (ab)+ matches ababab - that is, the +applies to the group. For more on backreferences see below.
[ ] A character class - matches one of the characters c[uoa]t matches cut, cot or cat.
[^ ] Negative character class - matches any character not specified c[^/]t matches cat or c=t but not c/t

In mod_rewrite the ! character can be used before a regular expression to negate it. This is, a string will be considered to have matched only if it does not match the rest of the expression.

Regex Back-Reference Availability

One important thing here has to be remembered: Whenever you use parentheses in Pattern or in one of the CondPattern, back-references are internally created which can be used with the strings$N and %N (see below). These are available for creating the strings Substitution and TestString. Figure 2 shows to which locations the back-references are transferred for expansion.

[Needs graphics capability to display]

Figure 2: The back-reference flow through a rule.

  • back-references ($N) to the RewriteRule Pattern
  • back-references (%N) to the last matched RewriteCond CondPattern

top

RewriteRule basics

A RewriteRule consists of three arguments separated by spaces. The arguments are

  1. Pattern: which incoming URLs should be affected by the rule;
  2. Substitution: where should the matching requests be sent;
  3. [flags]: options affecting the rewritten request.

The Pattern is always a regular expression matched against the URL-Path of the incoming request (the part after the hostname but before any question mark indicating the beginning of a query string).

The Substitution can itself be one of three things:

A full filesystem path to a resource

RewriteRule ^/games.* /usr/local/games/web

This maps a request to an arbitrary location on your filesystem, much like the Aliasdirective.

A web-path to a resource

RewriteRule ^/foo$ /bar

If DocumentRoot is set to /usr/local/apache2/htdocs, then this directive would map requests for http://example.com/foo to the path/usr/local/apache2/htdocs/bar.

An absolute URL

RewriteRule ^/product/view$ http://site2.example.com/seeproduct.html [R]

This tells the client to make a new request for the specified URL.

The Substitution can also contain back-references to parts of the incoming URL-path matched by the Pattern. Consider the following:

RewriteRule ^/product/(.*)/view$ /var/web/productdb/$1

The variable $1 will be replaced with whatever text was matched by the expression inside the parenthesis in the Pattern. For example, a request forhttp://example.com/product/r14df/view will be mapped to the path/var/web/productdb/r14df.

If there is more than one expression in parenthesis, they are available in order in the variables $1,$2, $3, and so on.

top

Rewrite Flags

The behavior of a RewriteRule can be modified by the application of one or more flags to the end of the rule. For example, the matching behavior of a rule can be made case-insensitive by the application of the [NC] flag:

RewriteRule ^puppy.html smalldog.html [NC]

For more details on the available flags, their meanings, and examples, see the Rewrite Flagsdocument.

top

Rewrite conditions

One or more RewriteCond directives can be used to restrict the types of requests that will be subject to the following RewriteRule. The first argument is a variable describing a characteristic of the request, the second argument is a regular expression that must match the variable, and a third optional argument is a list of flags that modify how the match is evaluated.

For example, to send all requests from a particular IP range to a different server, you could use:

RewriteCond %{REMOTE_ADDR} ^10\.2\.
RewriteRule (.*) http://intranet.example.com$1

When more than one RewriteCond is specified, they must all match for the RewriteRule to be applied. For example, to deny requests that contain the word "hack" in their query string, except if they also contain a cookie containing the word "go", you could use:

RewriteCond %{QUERY_STRING} hack
RewriteCond %{HTTP_COOKIE} !go
RewriteRule .* - [F]

Notice that the exclamation mark specifies a negative match, so the rule is only applied if the cookie does not contain "go".

Matches in the regular expressions contained in the RewriteConds can be used as part of theSubstitution in the RewriteRule using the variables %1, %2, etc. For example, this will direct the request to a different directory depending on the hostname used to access the site:

RewriteCond %{HTTP_HOST} (.*)
RewriteRule ^/(.*) /sites/%1/$1

If the request was for http://example.com/foo/bar, then %1 would contain example.comand $1 would contain foo/bar.

top
top

.htaccess files

Rewriting is typically configured in the main server configuration setting (outside any<Directory> section) or inside <VirtualHost> containers. This is the easiest way to do rewriting and is recommended. It is possible, however, to do rewriting inside <Directory>sections or .htaccess files at the expense of some additional complexity. This technique is called per-directory rewrites.

The main difference with per-server rewrites is that the path prefix of the directory containing the.htaccess file is stripped before matching in the RewriteRule. In addition, the RewriteBaseshould be used to assure the request is properly mapped.

Wednesday, August 4, 2010

How to Set Up A Custom 404 File Not Found Page on Apache

http://webdesign.about.com/od/apache/ht/ht404apache.htm
  1. Create a Web page that will be your 404 document.
  2. Open yourhttpd.conffile or .htaccess for editing.
  3. Find the line that reads (or add the line)
     ErrorDocument 404 /404.html
  4. Change the third entry to the URI you would like to display, e.g.
     ErrorDocument 404 /new_404.html
  5. Restart your Web server if necessary.

Featured Post

Windows和Ubuntu双系统完全独立的安装方法

http://www.ubuntuhome.com/windows-and-ubuntu-install.html  | Ubuntu Home Posted by Snow on 2012/06/25 安装Windows和Ubuntu双系统时,很多人喜欢先安装windows,然...