http://forum.modrewrite.com/
All this and more
---
URL Redirection with Mod-Rewrite
Creating the Rules
The Building Blocks of Mod-Rewrite URL Redirection Rules: Special Characters
Along with regular expressions, mod-rewrite allows for the use of special characters. It's a good thing to understand what these are before you begin writing rules. (Mainly because you need one or more of them in almost every rule.)
RewriteRule tells the server to interpret the following information as a rule.
RewriteCond tells the server to interpret the following information as a condtion of the rule(s) that are immediately after it.
^ defines the begining of a 'line' (starting anchor). Remember, ^ also designates 'not' in a regular expression, so please don't get confused.
( ) creates a variable to be stored and possibly used later, and is also used to group text.
$ defines the ending of a 'line' (ending anchor), and also defines a variable that comes from the RewriteRule (used for variables on the right side of the equasion or to match a variable from the rule in a condition, see example below).
% defines a variable that comes from a rewrite condition. (used for variables on the right side of the equasion only, see example below)
* The right side of the equasion is everything that follows the $ in a RewriteRule.
Examples: All variables are given a number according to the order they appear, the following rule and condition each have two variables, defined by parenthesis, so to use them you would put them where you need them in the results:
(the '-' is for spacing only to make the line more readable, and is not necessary to use variables.)
RewriteRule ^(var1)/no-var/(var2)$ /to-use-variables-type-$1-and-$2
The final result would look like this:
to-use-variables-type-var1-and-var2
RewriteCond %{CONDITION_STUFF} ^(var1)/no-var/(var2)
RewriteRule ^no-var/no-var/no-var$ /to-use-variables-type-%1-and-%2
The final result would look like this:
to-use-variables-type-var1-and-var2
To use a combination of the Condition and Rule Variables
RewriteCond %{CONDITION_STUFF} ^(var1)/no-var/(var2)
RewriteRule ^(var1)/no-var/(var2)$ /to-use-variables-type-$1-and-%2-$2
The final result would look like this: to-use-variables-type-var1-and-var2-var2
The only exception to the above examples is, you can also use the %{CONDITION_STUFF} in the right side of a rule, but it must appear exactly as in the condition: RewriteRule ^(var1)/no-var/(var2)$ /type-%{CONDITION_STUFF}
|(bar) stands for 'or', normally used with text or expressions grouped with parenthesis (EG (with|without) matches the string 'with' or the string 'without'. Keep in mind since these are inside parenthesis, the match is stored as a variable.)
\ is called an escaping character, this removes the function from a 'special character' (EG if you needed to match index.php?, which has both a .(dot) and a ?, you would have to 'escape' the special characters .(dot) and ? with a \ to remove their 'special' value it looks like this: index\.php\?)
! is like the ^ in a regular expression and stands for 'not', but can only be used at the beginning of a rule or condition, not in the middle.
- on the right side of the equasion stands for 'No Rewrite.' (It is often used in conjunction with a condition to check and see if a file or directory exists.)
Mod-Rewrite Directives for URL Redirection
Directives, in mod-rewrite are what give you the control of the response sent by the server when a specific URL is requested. They are an integral part of the rule writing process, because they designate any special instructions that might be needed. (EG If I want to tell everyone a page is moved permanently, I can add R=301 to my rule and they will know.)
Directives follow the rule and the most often used, are enclosed with [ ] (Not all directives are covered here, but the main and widely used ones are.)
[R] stands for redirect. The default is 302, temporarily moved. This can be set to any number between 300 and 400, by entering it as [R=301] or [R=YourNumberHere], but 301 (permanently moved) and 302 (temporarily moved) are the most common.
(If you just use [R] this will work, and defaults to 302, or temporarily moved)
** Do not use this 'flag' or directive if you are trying to have a 'silent' redirect.
[F] stands for forbiden. Any URL or file that matches the rule (and condition(s) if present) will return FORBIDEN to anyone who tries to access them. (Useful for files that you would like to keep private, or you do not want indexed prior to 'going live' with them.)
[G] stands for gone. (It's like Not Found, only different.) Not recommended for use yet, this is a newer rule/message (410 code) and many browsers and user-agents, like googlebot do not understand them yet.
[P] stands for proxy. This creates a type of 'silent redirect' for files or pages that are not actually part of your site and can be used to serve pages from a different host, as though they were part of your site. (DO NOT mess with copywritten material, some of us get very upset.)
[NC] stands for 'No Case' as applied to letters, so if you use this on a rule, MYsite.com, will match mysite.com... even though they are not the same. (This can also be used with regular expressions, so instead of [a-zA-Z], you can use [a-z] and [NC] at the end of the rule for the same effect.)
[QSA] stands for Query String Append. This means the 'query string' (stuff after the ?) should be passed from the original URL (the one we are rewriting) to the new URL.
[L] stands for last rule. As soon as this 'flag' or directive is read, no other rules are processed. (Every rule should contain this flag, until you know exactly what you are doing.)
In an attempt to put together regular expressions and mod-rewrite special characters here are some examples of what they do:
Goal: to match any lowercase words, or group of letters:
Possible Matches: lfie, page, site, or information
Expression: [a-z]+
Explaination: [a-z] matches any single letter. + matches 1 or more of the previous character or string of characters. When you put the two together you have a regular expression that matches any single letter from a to z over and over, until it runs into a character that is not a letter.
Goal: to match any words, or groups of letters, and store them in a variable:
Possible Matches: lfie, Page, site, or InforMation
Expression: ([a-z]+) [NC]
Explaination: Same as above with the addition of () and [NC]. In mod-rewrite, () creates a single variable out of the regular expression, so the word matched is now in a variable. [NC] stands for 'No Case' (from mod-rewrite) makes it so the regular expression or regular text strings, match both upper and lowercase letters, so with this expression you can match any single word.
Goal: to match any word, or group of letters, then any single number, and store them in separate variables:
Possible Matches: lfie1, Page2, site6, or InforMation9
Expression: ([a-z]+)([0-9]) [NC]
Explaination: Same as above, except notice there is no + in the number expression. This way only a single number will match.
Goal: to match any word, or group of letters, then any single number, and store them in the same variable:
Possible Matches: lfie1, Page2, site6, or InforMation9
Expression: ([a-z]+[0-9]) [NC]
Explaination: Same as above, except notice the plus is immediately following (no space) the [a-z], but before the [0-9] (again no space), so the + affects the [a-z], but not the [0-9].
Goal: to match any word, or group of letters, then any group of numbers, and store them in the same variable:
Possible Matches: lfie11, Page2, site642, or InforMation9987653
Expression: ([a-z]+[0-9]+) [NC]
Explaination: Same as above with the addition of a + immediately following to the numerical expression to match 1 or more numbers instead of only 1.
Goal: to match any word, or group of letters, any group of numbers, and any random letters and numbers, which might or might not be mixed together:
Possible Matches: 11, gPaE, s17ite642, or 2CreateInfo4UisCool
Expression: ([a-z0-9]+) [NC]
Explaination: the change here is to the regular expression grouping. Putting a-z and 0-9 in the same grouping followed by [NC] matches any combination of letters and numbers.
Goal: to match any word, or group of letters, then a single /, then any group of numbers, and store only the numbers in a variable.
Possible Matches: lfie/10, gPaE/1, site/642, or CreateInfoUisCool/2474890
Expression: [a-z]+/([0-9]+) [NC]
Explanation: Using the [a-z]+ without () matches the letters as usual. By putting the / outside of any expression, the only thing that will match is the exact character of /. Then using the ([0-9]+) again, stores any group of numbers in a variable.
Goal: to match anything before the / and store it in a variable, then match anything after the / and store it in a separate variable:
Possible Matches: lfie/10.html, gP..aE/1page_two.file, si&#te/642-your-site, or
CreateInfo/245390.php
Expression: ([^/]+)/(.+)
Explaination: Using two new forms of regular expressions, this is actually easier than it may seem. Making use of the ^(not) character, matches anything that is not a / and the () again save it in a variable. Then using the same form as above, the single, exact character of / is matched. Finally, the .(dot) character is used, because it matches any single character that is not the end of a line, and when combined with the + character, matches anything up to a line break. Once again () are used to create the variable. *Also, notice the use of a 'catch-alls' eliminates the need for the [NC] 'flag' of mod-rewrite.
If this was a full regular expression site, I would continue, but you should have an idea of how regular expressions work, so, time to move on...
Things to Remember About Mod-Rewrite URL Redirection
1. If you are using a condition(s) they always relate to the rule(s) that immediately follow them.
2. Mod-Rewrite will always try to match a URL to a rule before it checks the conditions, so if no rules match, the conditions are never checked.
3. After a URL request matches a rule, and changes are applied, the request is sent back to the main configuration file and treated like it is a new URL request.
(This is the cause of an infinite loop, and with a regular expression and variables, it is sometimes easy to miss. The following examples show very simply how it happens... there are cases where two or three or more rules write to each other and have the same effect.)
Pretend someone wanted to go to your site and a visit a page called 'letters.html', but you wanted to redirect them somewhere else like 'numbers.html':
They request the URL:
http://yoursite.com/letters.html
Your rule catches their URL request:
RewriteRule ^([a-z]+)\.html$ /numbers.html [R,NC,L]
Your rule then rewrites their request to the URL:
http://yoursite.com/numbers.html
Their request starts over like it is a new request for the URL:
http://yoursite.com/numbers.html
Your rule catches their URL request, because you are using a regular expression that catches all letters:
RewriteRule ^([a-z]+)\.html$ /numbers.html [R,NC,L]
Your rule then rewrites their request to the URL:
http://yoursite.com/numbers.html
Their URL request starts over like it is a new request for:
http://yoursite.com/numbers.html
Eventually they see 500-server error, or maximum redirects exceeded, or your server melts and your hosting company calls you and wants to know, why? (Kidding about the server melting, but rewrite rules can be placed in the server set-up and force a restart, to break an infinite loop.)
Keep in mind, this did not happen, because your rule didn't work... It worked too well, over and over and over...
Wednesday, June 24, 2009
Tuesday, June 16, 2009
USBConnect Mercury
http://docs.google.com/Doc?id=d9khzpw_0w4m774dd
- Update the file /usr/share/hal/fdi/information/10freedesktop/10-modem.fdi by adding the following lines at the top of the section marked with the "" as shown below:
- Before:
IS-707-A
- After (add the highlighted lines):
GSM-07.07
GSM-07.05
IS-707-A
- Restart hal using the following command:
sudo /etc/init.d/hal restart
- Insert the Sierra Wireless USBConnect Mercury modem into a USB port of the machine. NetworkManager should prompt you for modem configuration in a few seconds.
AT&T USBConnect QuickSilver
http://6head.blogspot.com/2008/12/now-to-3g-wireless-working.html
So to get started you will want install a repo to enable access to rezero. You need this becasuse this USB modem has the drivers built into the device. When you insert the USB modem with out the use of rezero it will register as a CD and not as a Modem. Rezero will switch the devices mode from storage device to modem, which is what you want. option has made available an updated version of this software called "ozerocdoff". But I could not figure out how to install it and rezero worked just fine for me.
Install Rezero:
Paste this into your list of third-party repositories in synaptic. Located in System -->Administration -->Synaptic.
Monday, December 1, 2008
Now to Get 3G Wireless Working (AT&T USBconnect Quicksilver)
If you have Ubuntu running on a PC, Here are the steps to successfully get the AT&T USBconnect Quicksilver. I have to give a HUGE thanks out to Paul at PHARscape for helping me get this working. While Ubuntu 8.10 has a connection manager capable of configuring a WAN wifi connection, it does not support all of the latest USB devices at this time. Have no fear, it is really rather simple to get working now that there are files you can easily install via .deb.So to get started you will want install a repo to enable access to rezero. You need this becasuse this USB modem has the drivers built into the device. When you insert the USB modem with out the use of rezero it will register as a CD and not as a Modem. Rezero will switch the devices mode from storage device to modem, which is what you want. option has made available an updated version of this software called "ozerocdoff". But I could not figure out how to install it and rezero worked just fine for me.
Install Rezero:
Paste this into your list of third-party repositories in synaptic. Located in System -->Administration -->Synaptic.
deb http://ppa.launchpad.net/martijn/ubuntu intrepid mainRemember to click reload. Then search for Rezero and install it. Now if you plugin your USB modem it will no loger be seen as a storage device.
Tuesday, June 2, 2009
Debt Avalanche
http://www.consumerismcommentary.com/2008/07/07/the-correct-way-to-pay-off-personal-debt-the-debt-avalanche/
The Correct Way to Pay Off Personal Debt: The Debt Avalanche
by Flexo
When it comes to mathematics, certain facts are universally agreed-upon. For example, regardless of your culture or educational system, you must agree that one plus one equals two unless you mistakenly fall for an invalid proof. When dealing with money, why are people inclined to believe that one plus one does not equal two?
If you have a certain amount of money available to pay off a portion of your debt each month, even if that certain amount changes, there is a mathematically correct way of paying off that debt. You can call this approach the Debt Avalanche. It is similar to Dave Ramsey’s popular “debt snowball” method, with one small but important detail: With the Debt Avalanche you will pay off your debt faster and pay less total interest to banks and lenders.
The simple calculation for the Debt Avalanche requires only the interest rates for each debt account. This assumes that all debt accounts have the same tax liability, but if that’s not the case, determine your interest rate after taxes for this calculation.
Step 1. Order your debts from highest interest rate to lowest. You may find credit cards at the top of the list. It’s typical to see interest rates from 10% to 20% or more. Credit cards offered by stores often have the highest interest rates, so you might find these at the very top. Watch out for promotional rates ending, which they may do on the date promised when you enrolled, or earlier. Card issuers also re-evaluate their customers every so often, and will not think twice about raising your rates midstream. Note that if your credit improves, they will not magically lower your rates. While lenders will notify you if they intend to raise your rates, you may have missed the notice.
Your mortgage and home equity loan may be the next debts in line. It’s important for your list to capture every debt for which you make a monthly payment. Student loans may be the last on the list, particularly if you qualify for tax credits. The Debt Avalanche formula won’t work properly if it covers only a portion of your debt, so consider all accounts.
Order your list from the highest interest rate (after tax) to the lowest. You may have noticed we didn’t factor in your account balances in the above formula. That is because your individual account balances are irrelevant. The issue solved by the Debt Avalanche is the best way to pay off your total debt with all available funds.
Step 2. Pay the minimum to all debts every month. If you’re writing down your list, or using a spreadsheet like Excel, add a column next to each debt to list its minimum monthly payment. This is the amount you will pay towards each debt, except for the one account listed at the top of the list.
Another column should list the payment due date if it is relatively static from month to month. For example, my credit card payment is due on the last date of almost every month, so I would write “30.” This would indicate to me the last date of every month. Your payments should always arrive before the due date. In fact, in some cases, you can reduce your total interest paid by paying weeks in advance of your due date.
Step 3. To your debt with the highest interest, send all extra available cash. If you have an emergency fund, this step is simple. Since it’s unlikely that you can earn more in savings than you can “earn” (reclaim) by paying off your debt, all your unused income after paying expenses (necessary and discretionary as you see fit) should be dedicated towards the debt account with the highest interest rate.
Step 4. Repeat every month. You cover all your bases by ensuring every creditor receives the minimum payment, but you hone in on only your debt with the highest interest. Once a debt account has been eliminated — and it may not be the account at the top of the list if other balances are smaller — remove it from the list and re-order if interest rates have changed.
It’s that simple. This is mathematically the best method for paying off your personal debt. No other method will get you out of debt faster and save you as much money.
Despite the facts, many people disagree. The primary reason detractors, or supporters of the “debt snowball” method, may argue is that Dave Ramsey’s method will help you pay off your smaller debt faster, providing you with “early success” and possibly the motivation to continue along the path of debt reduction. The Debt Avalanche will also provide early success, but if you need special motivation to continue your monthly payments, consider this: By choosing the Debt Avalanche method, you will pay off your total debt faster, you will pay less interest, and you are mathematically efficient.
That is motivation enough. Or is it?
Dave Ramsey believes his “debt snowball” method, in which debts are paid off in the order of balance from lowest to highest, has shown better results than any other method thanks to “quick wins.” If he were to ask his followers if they want to carry their debt longer and pay more interest throughout before offering the “debt snowball” method, they would choose the faster, cheaper, better option of the Debt Avalanche.
One of the many reasons people can fall into debt is the difficulty of separating emotional thinking from rational thinking. The Debt Avalanche helps separate these two methods of thinking, as the best financial decisions are almost always the rational decisions. But it helps to pay attention to some of the psychology involved, as well.
The possible motivation due to the “early success” aspect of the debt snowball method is cited by many followers to be its strongest point, encouraging debt reducers to continue down the path. Followers of the mathematically and financially superior Debt Avalanche, if they need this sort of motivation, can achieve the same effect by defining milestones.
Rather than “celebrating” when your first full credit card or other debt account is paid off, take note and reward yourself when you’ve paid off your first $1,000 (or $500 or $10,000, whatever is applicable to you). Setting and achieving these short term goals influences the same area of the brain (the mesolimbic system) as the act of paying off the first credit card and are similar enough to provide the same motivational results.
Quick wins may help to motivate debt reducers to continue along the path, but the real win comes in knowing you’ve made the smarter choice.
The Correct Way to Pay Off Personal Debt: The Debt Avalanche
by Flexo
When it comes to mathematics, certain facts are universally agreed-upon. For example, regardless of your culture or educational system, you must agree that one plus one equals two unless you mistakenly fall for an invalid proof. When dealing with money, why are people inclined to believe that one plus one does not equal two?
If you have a certain amount of money available to pay off a portion of your debt each month, even if that certain amount changes, there is a mathematically correct way of paying off that debt. You can call this approach the Debt Avalanche. It is similar to Dave Ramsey’s popular “debt snowball” method, with one small but important detail: With the Debt Avalanche you will pay off your debt faster and pay less total interest to banks and lenders.
The simple calculation for the Debt Avalanche requires only the interest rates for each debt account. This assumes that all debt accounts have the same tax liability, but if that’s not the case, determine your interest rate after taxes for this calculation.
Step 1. Order your debts from highest interest rate to lowest. You may find credit cards at the top of the list. It’s typical to see interest rates from 10% to 20% or more. Credit cards offered by stores often have the highest interest rates, so you might find these at the very top. Watch out for promotional rates ending, which they may do on the date promised when you enrolled, or earlier. Card issuers also re-evaluate their customers every so often, and will not think twice about raising your rates midstream. Note that if your credit improves, they will not magically lower your rates. While lenders will notify you if they intend to raise your rates, you may have missed the notice.
Your mortgage and home equity loan may be the next debts in line. It’s important for your list to capture every debt for which you make a monthly payment. Student loans may be the last on the list, particularly if you qualify for tax credits. The Debt Avalanche formula won’t work properly if it covers only a portion of your debt, so consider all accounts.
Order your list from the highest interest rate (after tax) to the lowest. You may have noticed we didn’t factor in your account balances in the above formula. That is because your individual account balances are irrelevant. The issue solved by the Debt Avalanche is the best way to pay off your total debt with all available funds.
Step 2. Pay the minimum to all debts every month. If you’re writing down your list, or using a spreadsheet like Excel, add a column next to each debt to list its minimum monthly payment. This is the amount you will pay towards each debt, except for the one account listed at the top of the list.
Another column should list the payment due date if it is relatively static from month to month. For example, my credit card payment is due on the last date of almost every month, so I would write “30.” This would indicate to me the last date of every month. Your payments should always arrive before the due date. In fact, in some cases, you can reduce your total interest paid by paying weeks in advance of your due date.
Step 3. To your debt with the highest interest, send all extra available cash. If you have an emergency fund, this step is simple. Since it’s unlikely that you can earn more in savings than you can “earn” (reclaim) by paying off your debt, all your unused income after paying expenses (necessary and discretionary as you see fit) should be dedicated towards the debt account with the highest interest rate.
Step 4. Repeat every month. You cover all your bases by ensuring every creditor receives the minimum payment, but you hone in on only your debt with the highest interest. Once a debt account has been eliminated — and it may not be the account at the top of the list if other balances are smaller — remove it from the list and re-order if interest rates have changed.
It’s that simple. This is mathematically the best method for paying off your personal debt. No other method will get you out of debt faster and save you as much money.
Despite the facts, many people disagree. The primary reason detractors, or supporters of the “debt snowball” method, may argue is that Dave Ramsey’s method will help you pay off your smaller debt faster, providing you with “early success” and possibly the motivation to continue along the path of debt reduction. The Debt Avalanche will also provide early success, but if you need special motivation to continue your monthly payments, consider this: By choosing the Debt Avalanche method, you will pay off your total debt faster, you will pay less interest, and you are mathematically efficient.
That is motivation enough. Or is it?
Dave Ramsey believes his “debt snowball” method, in which debts are paid off in the order of balance from lowest to highest, has shown better results than any other method thanks to “quick wins.” If he were to ask his followers if they want to carry their debt longer and pay more interest throughout before offering the “debt snowball” method, they would choose the faster, cheaper, better option of the Debt Avalanche.
One of the many reasons people can fall into debt is the difficulty of separating emotional thinking from rational thinking. The Debt Avalanche helps separate these two methods of thinking, as the best financial decisions are almost always the rational decisions. But it helps to pay attention to some of the psychology involved, as well.
The possible motivation due to the “early success” aspect of the debt snowball method is cited by many followers to be its strongest point, encouraging debt reducers to continue down the path. Followers of the mathematically and financially superior Debt Avalanche, if they need this sort of motivation, can achieve the same effect by defining milestones.
Rather than “celebrating” when your first full credit card or other debt account is paid off, take note and reward yourself when you’ve paid off your first $1,000 (or $500 or $10,000, whatever is applicable to you). Setting and achieving these short term goals influences the same area of the brain (the mesolimbic system) as the act of paying off the first credit card and are similar enough to provide the same motivational results.
Quick wins may help to motivate debt reducers to continue along the path, but the real win comes in knowing you’ve made the smarter choice.
Subscribe to:
Posts (Atom)