cherokee / webserver

Cherokee Web Server
GNU General Public License v2.0
563 stars 104 forks source link

Response code Rule List #736

Open danielniccoli opened 11 years ago

danielniccoli commented 11 years ago

Original author: pchott@gmail.com (October 04, 2010 06:19:21)

Due SEO request Rule List maybe should some types, like Apache rewrite

R=301 L - last rule NC - not case sensitive ...

Original issue: http://code.google.com/p/cherokee/issues/detail?id=1012

danielniccoli commented 11 years ago

From alobbs on October 04, 2010 10:33:41 It'd make sense to add a new "Case insensitive" flags in the different rule types, indeed. The 'L' looks like what we refer as a Final Rule, although I must confess I'm not complete sure about it.

danielniccoli commented 11 years ago

From pchott@gmail.com on October 04, 2010 11:01:52 unixwars has already ask me to write little elaborating about this. I'll write as soon i have little more time.

danielniccoli commented 11 years ago

From alobbs on October 04, 2010 11:07:12 @pchott: Superb. That will be extremely useful, actually. Thanks!

danielniccoli commented 11 years ago

From pchott@gmail.com on October 04, 2010 11:28:58 The most common is while rewriting urls for SEO to have nicer urls, server should not response with 200 ok, but 301 permanent redirect, other wise bots detects duplicate content and lower the page rank.

Here is the first info in found.

R[=code] Redirect to new URL, with optional code (see below). Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force a external redirection. If no code is given a HTTP response of 302 (MOVED TEMPORARILY) is used. If you want to use other response codes in the range 300-400 just specify them as a number or use one of the following symbolic names: temp (default), permanent, seeother. Use it for rules which should canonicalize the URL and give it back to the client, e.g., translate /~'' into/u/'' or always append a slash to /u/user, etc. Note: When you use this flag, make sure that the substitution field is a valid URL! If not, you are redirecting to an invalid location! And remember that this flag itself only prefixes the URL with http://thishost[:thisport]/, rewriting continues. Usually you also want to stop and do the redirection immediately. To stop the rewriting you also have to provide the 'L' flag. 301 Moved permanently 302 Moved temporarily 403 Forbidden 404 Not found 410 Gone

F Forbidden (sends 403 header) This forces the current URL to be forbidden, i.e., it immediately sends back a HTTP response of 403 (FORBIDDEN). Use this flag in conjunction with appropriate RewriteConds to conditionally block some URLs.

G Gone (no longer exists) This forces the current URL to be gone, i.e., it immediately sends back a HTTP response of 410 (GONE). Use this flag to mark pages which no longer exist as gone.

P Proxy This flag forces the substitution part to be internally forced as a proxy request and immediately (i.e., rewriting rule processing stops here) put through the proxy module. You have to make sure that the substitution string is a valid URI (e.g., typically starting with http://hostname) which can be handled by the Apache proxy module. If not you get an error from the proxy module. Use this flag to achieve a more powerful implementation of the ProxyPass directive, to map some remote stuff into the namespace of the local server. Notice: To use this functionality make sure you have the proxy module compiled into your Apache server program. If you don't know please check whether mod_proxy.c is part of the httpd -l'' output. If yes, this functionality is available to mod_rewrite. If not, then you first have to rebuild thehttpd'' program with mod_proxy enabled.

L Last Rule Stop the rewriting process here and don't apply any more rewriting rules. This corresponds to the Perl last command or the break command from the C language. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. For example, use it to rewrite the root-path URL ('/') to a real one, e.g., '/e/www/'.

N Next (i.e. restart rules) Re-run the rewriting process (starting again with the first rewriting rule). Here the URL to match is again not the original URL but the URL from the last rewriting rule. This corresponds to the Perl next command or the continue command from the C language. Use this flag to restart the rewriting process, i.e., to immediately go to the top of the loop. But be careful not to create an infinite loop!

C Chain This flag chains the current rule with the next rule (which itself can be chained with the following rule, etc.). This has the following effect: if a rule matches, then processing continues as usual, i.e., the flag has no effect. If the rule does not match, then all following chained rules are skipped. For instance, use it to remove the .www'' part inside a per-directory rule set when you let an external redirect happen (where the.www'' part should not to occur!).

NS Skip if internal sub-request This flag forces the rewriting engine to skip a rewriting rule if the current request is an internal sub-request. For instance, sub-requests occur internally in Apache when mod_include tries to find out information about possible directory default files (index.xxx). On sub-requests it is not always useful and even sometimes causes a failure to if the complete set of rules are applied. Use this flag to exclude some rules. Use the following rule for your decision: whenever you prefix some URLs with CGI-scripts to force them to be processed by the CGI-script, the chance is high that you will run into problems (or even overhead) on sub-requests. In these cases, use this flag.

NC Case insensitive This makes the Pattern case-insensitive, i.e., there is no difference between 'A-Z' and 'a-z' when Pattern is matched against the current URL.

QSA Append query string This flag forces the rewriting engine to append a query string part in the substitution string to the existing one instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.

S=x Skip next x rules This flag forces the rewriting engine to skip the next num rules in sequence when the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause becomes skip=N where N is the number of rules in the else-clause. (This is not the same as the 'chain|C' flag!)

E=var:value Set environment variable "var" to "value" This forces an environment variable named VAR to be set to the value VAL, where VAL can contain regexp backreferences $N and %N which will be expanded. You can use this flag more than once to set more than one variable. The variables can be later dereferenced in many situations, but usually from within XSSI (via ) or CGI (e.g. $ENV{'VAR'}). Additionally you can dereference it in a following RewriteCond pattern via %{ENV:VAR}. Use this to strip but remember information from URLs.

Some more info about ReWrite rules that apache uses: http://borkweb.com/story/apache-rewrite-cheatsheet

​##### SEO important

So what happens to the link juice if you DON'T use a 301?

Nothing. It's all there. You do your link-building externally to the pretty URL, and you link to the pretty URL from within your website. As far as Googlebot is concerned /products/necklaces/purple-amethyst-necklace-11623 REALLY exists, it's got all this great content (from your database), and when Googlebot requests that page, they get all that juicy content back, along with a swell little HTTP 200 (OK) status code.

http://www.seomoz.org/knowledge/redirection

i suggest that in addition to Rule list is added optional aditional parameters.

@alobbs: If you need some more info, please ask and i'll try to help or search over net