In Depth: Are wireless signals really dangerous?

In Depth: Are wireless signals really dangerous?

In Depth: Are wireless signals really dangerous?
While we are surrounded by radio waves emitted by the Cosmos, we have only known about them since the 1890s, when wireless transmission was first demonstrated.
However, It wasn't until the late 1980s, with the advent of the first mobile phones, that radio transmitters first started entering the home, and even then, it took until the early-to-mid 1990s before mobile phones became commonplace. The mid-1990s also saw the first consumer use of wireless networks, and just as with phones, only took a few years to become mass-market products.
Look around a modern home and you will see that we are now surrounded by devices which emit radio waves, from our mobile phones to laptops and tablets, wireless routers, baby monitors, cordless phones, wireless games console controllers, some TV and Hi-Fi remotes (although most use Infra Red), wireless burglar alarm systems, Bluetooth headsets, keyboards and mice, wireless weather stations and more.
Galaxy S3
So does all this electromagnetic radiation pose any sort of health risk to us? This is a question that many scientists have been struggling to answer and it seems that trying to get a definitive answer is not easy.
There's no doubt that Radio Frequency (RF) energy can be powerful and dangerous. Microwaves ovens use radio waves to heat food, which is why they need proper shielding to be safe. High-powered radio transmitters, such as those used on military vehicles, have warnings to keep away from the antenna, because coming into contact with it while the radio is transmitting can give you a nasty burn (known as RF burn).
Microwave ovens use a frequency around 2,450MHz (2.45GHz), Bluetooth 2,400MHz to 2,408MHz, and Wireless LAN uses 2,412MHz to 2,484MHz. Other devices, such as baby monitors and burglar alarms tend to use FM frequencies (e.g. 433MHz).
Mobile phones vary from country to country and cover a wide spectrum of frequencies although the most popular are 850MHz, 900MHz, 1,800MHz and 1,900Mhz. While any radio wave with a frequency between 300Mhz and 300GHz is classed as a microwave, it doesn't mean that they all have the same characteristics.

How bad are microwaves?

Microwave ovens are able to heat food for three reasons; the waves are highly focused, the metal box of the oven prevents the waves from dispersing, therefore they are fully absorbed by whatever is in the oven and thirdly, the emission power is very high (up to 1,000w). In contrast, a Bluetooth headset, wireless land or mobile phone's RF emissions are unfocused and unconstrained, while the emission power is much lower.
Bluetooth devices range from 1mW to 100mW, Wireless LANs between 32mW and 200mW, while 3G mobile phones have a maximum power output of 2 Watts, but will typically be operating at around 500mW, although the first analogue phones had a peak output of 3.6W.
Microwave
From this it's fairly obvious that the amount of RF energy emitted by most devices, is incredibly low. However, any device which operates near the same frequencies as a microwave oven, i.e. around the 2GHz mark, could potentially generate some of the same effects, including localised heating of tissue. It is this heating effect which has led some to believe that microwave frequency radio waves are detrimental to health.

What about phones?

In 2011 the International Agency for Research on Cancer (IARC) classified mobile phones as possibly carcinogenic, although the World Health Organisation has said that "to date, no adverse health effects have been established as being caused by mobile phone use". A number of studies have been carried out, but as mobile phone use has only been widespread for around 15 years or so, so far, there has no direct evidence of a link between mobile phone use and cancer.
One of the largest studies was carried out in Denmark and involved around 420,000 people, who had been using mobile phones for 21 years (1982 to 1995). Despite the fact that the users would have been using the higher powered analogue phones, as well as lower-powered digital phones, the researchers concluded that there was no evidence for an association between tumour risk and mobile phone use, even in long-term users.
Bluetooth
So what about other health risks? There have been many stories which claim that RF exposure can interfere with sleep patterns. Research here is contradictory, with one Finnish study showing no ill effects, others have found that pulsed RF can have an effect on the brain. Some people even believe that being soaked in radio waves has other effects upon the body, such as fatigue, lack of concentration, headaches or memory issues, and this is known as Electromagnetic Hypersensitivity.
However, in 2010, a review of 46 studies into electromagnetic sensitivity found that there was no robust evidence for the existence of electromagnetic hypersensitivity. In double-blind tests, those who claim to suffer from hypersensitivity were unable to conclusively determine whether a RF emitting device is on or off.

Reducing exposure

While RF emission power levels are regulated by national legislation, some manufacturers, it seems, take extra steps to reduce your exposure. It has been discovered that in Apple's latest iPad, there is apparently a proximity sensor, which will reduce the power of the device's 3G radio, when it detects a solid object (such as any part of your body) within 10mm top of the screen. However, according to Pong Research, it's not just human tissue which triggers the sensor, most iPad cases do as well.
Ipad mini
Pong does have a vested interest in these claims, however, as it markets a range of cases which it claims not only stop the proximity sensor of the iPad activating, when fitted with a case, but which also direct the RF energy of your mobile device away from your head., using a passive, coupled antenna. Unfortunately these are claims we can't verify, as we simply don't have access to the necessary testing equipment, however, Wired has an extensive writeup on Pong's claims and comes to the conclusion that yes, these cases do in fact live up to their claims, when tested in a compliance testing lab.
One of the points Pong makes is that most SAR (Specific Absorption Rate – a measure of how much RF energy is absorbed by the human body) tests are done on models of adults heads. The argument is that a child's head, especially one under the age of 10, has a much thinner skull than an adult and the brain is more vulnerable to the effects of RF radiation.
This is a fair point and while some more recent tests have been conducted using head models based on MRI scans of a child's head, most studies have been based on adults. Studies that have used models of a child's head have shown increased absorption of microwave frequency radio waves.
Pong
So, the question is, should you be worried about the emissions your wireless devices are giving off? This is the billion-dollar question and to our minds, still hasn't been answered. So far the evidence would suggest that adult users are at very low risk, but more research needs to be done. For children, the risks would certainly appear to be higher. Trying to police your child's phone use is probably impossible, so reducing exposure seems like the next best option.
Using a Bluetooth headset is certainly one way to reduce the amount of RF radiation your head is exposed to from your phone, although they are not the easiest things to use and far too easy to misplace. Using a case that directs radiation away from the head would seem to be the next best option and Pong's cases would certainly seem to fit the bill.

 

One Week Without A Smartphone? Impossible

One Week Without A Smartphone? Impossible 
 
OLYMPUS DIGITAL CAMERA
We live in a funny world, don’t we? There was a time when homes had a single phone. And when it rang, the kids in the house had to hope that mom or dad would let them talk for a while. If the phone rang too late, it meant one of two things: something was wrong, or one of the kids had a friend calling at an inappropriate time.
Soon, things changed, and homes had more telephones, providing a bit more leeway in the way communication was handled. It wasn’t until the introduction of the mobile phone that dramatically changed how we would communicate with others, and it caused a radical change in our lives.
Now, though, everywhere I turn, I find people with smartphones. From elders who grew up in a time when phone lines were shared to priests, just about everyone around us has a smartphone on their hip, in their pocket, or hiding in their purse. A smartphone isn’t just an accessory to many people, it’s an extension of their lives. And without it, there would be no way to live.
For me, such a scenario would be impossible to even fathom. Each morning, the first thing I do after saying good morning to my wife is check my smartphone to see if I’ve missed any important e-mails. I might also check the news to see what’s happening around the world. During the day, my smartphone is with me wherever I go, so I can send off a quick text, check e-mail when away from a computer, and surf the Web when I need to. Oh, and I might also place a call from time to time.
So, earlier this week as I was on my smartphone, I questioned whether I could stay away from it for just one week. What would my week be like, I thought. How would my life be different? Would things be better or worse?
'It wasn’t long before I had ‘technology withdrawals’' I decided after thinking that that it was time I explored the possibility of living without my smartphone for a week. So, for the rest of the day and a bit into the next day, I was smartphone-free. It wasn’t long, though, that I was desiring holding my smartphone in my hand and checking things. It also wasn’t long before I had what might only be called “technology withdrawals” — a seemingly chemical response in the brain to not having something I rely on to such a huge degree.
So, before long, I gave in and got my smartphone. I’m weak, perhaps, or just not very good at controlling myself. In either case, I realized that, for me, living without a smartphone isn’t even an option.
The next question, though, is, such an addiction good or bad? I can be more productive with my smartphone, but that I actually have it in-hand at all times and can’t let it go might liken it to something much worse.
So, I pose the question to you: can you (or, perhaps, would you) want to live without a smartphone for a week? Is it easier said than done? Don’t scoff so quickly and think it’ll be an easy task; it won’t. Be ready for a challenge. And be ready for the withdrawals.

One Week Without A Smartphone? Impossible is written by Don Reisinger & originally posted on SlashGear.
© 2005 - 2012, SlashGear. All right reserved.

How to Download Torrentz Files using IDM

Downloading torrents proves to be beneficial when its speed is at maximum. But most of the time we get low speed when seeders decreases or they reduce their uploading limit.To increase uploading limit of seeders is not in our hands but we can find alternative to improve our downloading speed.

One of the best practice is to download torrent file using IDM (Internet Download Manager), but question arises how can we download torrent files using IDM. Don't worry there's a simple way to do this using  zbigz which I have described below. Just follow few simple steps and you are done.



  1. First of all you need to search the torrent file link from where you can download torrent file.
  2. Download torrent file or you can just copy the link of the torrent file
  3. After copying the link address of the file that you want to download using IDM go to www.zbigz.com and paste the link address in input box provided by the site and press Go button.                                                        
  4. Or if you have downloaded torrent file then just click on upload file and browse to the location where you have saved torrent file and select it and press Go button.
  5. Select free account.
  6. Now the zbigz's server will download that file in its server and keep it for a week to  be download by client.
  7. It may take half an hour to get torrent downloaded by server depending on server load and seeders available.
  8. Once server has completed downloading it will avail you to download file using IDM.       
  9. Press on download and select free account that's it, your download will start using IDM.

How to get source code from apk file

What is .apk file?
 APK file is nothing but Android Package File(APK). APK is the file format used to distribute and install application software and middleware on Google's Android operating system.


Apk Files are Zip file formatted packages based on the JAR file format, with .apk extension. Apk files contains all program resources and code i.e it contains .dex files, resources, assets, certificates, and manifest file.



How to get source (java files) from .apk file?
As we now know that apk file is just a zip file containing all program resource file, we can now get java code from apk files with ease. Following are steps to get java code from apk files.
Step 1:Renaming .apk file
  • Rename the .apk file with the extension .zip (for example let the file be "demofile.apk" then after renaming it becomes "demofile.apk.zip")

Step 2:Getting java files from apk
  • Now extract the renamed zip file in specific folder, for example let that folder be "demofolder".
  • Now Download dex2jar from the link for windows and extract that zip file in folder "demofolder".
  • Now open command prompt and go to the folder created in previous step and type the command "dex2jar classes.dex" and press enter.This will generate "classes.dex.dex2jar" file in the same folder.
  • Now  Download java decompiler from the link and extract it and start(double click) jd-gui.exe
  • From jd-gui window browse the generated "classes.dex.dex2jar" file in demofolder, this will give all the class files by src name.
  • Now from the File menu select "save all sources" this will generate a zip file named "classes_dex2jar.src.zip" consisting of all packages and java files.
  • Extract that zip file (classes_dex2jar.src.zip) and you will get all java files of the application.
Above steps will generate java files but to get xml files perform following steps.

Step 3:Getting xml files from apk
  • Download apktool and apktool install from the link and extract both files and place it in the same folder (for example "demoxmlfolder").
  • Place the .apk file in same folder (i.e demoxmlfolder)
  • Now open command prompt and goto  the directory where apktool is stored (here "demoxmlfolder") and type the command "apktool if framework-res.apk" 
  • Above command should result in "Framework installed ..."
  • Now in command prompt type the command "apktool d filename.apk" (where filename is name of apk file)
  • This will generate a folder of name filename in current directory (here demoxmlfolder) where all xml files would be stored in res\layout folder

Ten websites that teach coding and a bunch of other things

Seemingly every day there’s a new article or blog post imploring you to learn how to code. “Those who code have the power to transform their dreams into reality.” “Coding will help you keep [your job], or help you make a case for a raise.” “You should learn to program because it’s easy, it’s fun, it will increase your skill set, and… it will fundamentally change your perspective on the world.” What’s more, “If you want to start a technology company, you should learn to code.” New York City Mayor Michael Bloomberg’s New Year’s resolution was to learn how to code. Douglas Rushkoff, who calls coding “the new literacy of the digital age,” wrote an entire book about it. And didn’t Marc Andreessen say that “software is eating the world?” As a result, companies from Codecademy to edx and many others have popped up to meet this rising demand.
As a person who’s grown up in the digital age, I have often heard the cry, “digital literacy or die.” Conventional wisdom – at least today – is that in the way you know how to read and write English, “you need to have some understanding of the code that builds the Web… It is fundamental to the way the world is organized and the way people think about things these days.” If you buy that then you’ll want to start now.
But where should you go? I’ve been dabbling in the black arts, although I am by no means a ninja coder, and am ready to report back. The courses below offer everything from HTML to Python and beyond. HTML and CSS are good, because they’re the basic building blocks of Web design, and in my opinion, Python is useful, because it’s the most universal in many respects. Others say Java is better to learn, because its so prominent on the Web. I would rebut that you can learn Java from Python. Potayto. Potahto.
In any case, each program below emphasizes different pedagogical techniques and  philosophies, and they are all mass market in the sense that anyone is welcome. No previous experience is necessary.

MIT Courseware Online
MIT has long been a pioneer of online courseware. One course is their Intro to Computer Science & Programming class, thought by many to be the best, most encompassing intro computing course offered. Taught by tenured MIT faculty, the online course is structured via taped lectures, written assignments, and self-assessment quizzes.
The course itself is quite rigorous as it was an intro course for MIT students. This isn’t a sort of online class you can do some parts and not the other.  It requires a certain amount of pre-existing math knowhow to be truly successful. The course description says it only requires high school algebra as a prerequisite but I don’t buy this. I remember being pretty stumped by the second assignment, and I passed AP Calc with flying colors. This doesn’t mean the math is terribly high-level, but that it probably requires a certain amount of mathematical aptitude beyond algebra unless you want to spend the entire course scouring forums for help. As with any MIT course, there is an expectation that you not only know how to do a function, but why that function is performed and from where it stemmed. After attempting to follow this courseware for two sessions, I was officially stumped and dropped it.

edX
MIT and Harvard partnered up to create edX. It is a conglomeration of all of their available open courseware, along with a new department for the two institutions to perform research about the future of online courses and new pedagogical technologies. For MIT courseware, you can watch the lectures anytime, read the assignments, and self-assess. EdX has you follow the course in real time and complete the assignments and exams to receive a physical certificate from the program. It currently offers numerous classes in more subjects than just coding and far beyond the purview of Computers Science.

Codecademy
Codecademy.com is something slightly different than the last two. It uses a curriculum of exercises to teach the basics of coding in a variety of languages (PHP, JScript, Java, Python, Ruby, etc.). It has a text box to write different codes, and a number of tasks written alongside as a way to teach different skill sets. It’s a useful program for people who want to dive in to coding and learn the basics from a more pragmatic level. Wired.com, in fact, listed it as one of the more successful venues for learning code. However, some of the pitfalls lie in its simplicity: it’s a series of exercises, and doesn’t teach you much beyond rote tasks. It attempts to provide some context, but it just scratches the surface (at least for the beginner courses). You are able to learn the commands, their meanings, etc., and sometimes that’s just it. Codecademy teaches you these basics; and what logically follows is the statement: “I learned code.” Beyond that, it doesn’t teach a deeper type of literacy, other than learning helpful coding tricks, for better or for worse.

Google University Consortium
Much in the same vein as Harvard and MIT, Google used to offer various online courses for its progam Google Code University. GCU has since retired, but Google has archived its Python and C++ classes, along with providing ways to search for other online university curricula. It is now displaying a wide range of other courses not from Google, and calling it the Google University Consortium in Google’s developers page. The offerings for coding and computing are scant. All I could find was a course on “Programming with Go”, and when I went to begin that course it was a YouTube video.
PHP Academy
PHP Academy is similar to Codecademy in that it’s a private, community-based site working to educate the world on web development. Its methods are a series of courses, that is, videos and forums for all who want to participate. The appearance is more scaled down than Codecademy and seems to target those who have some familiarity with coding. In that regard, PHP generally approaches coding as something you already know, or are at least familiar with, so its approach to literacy is that some foundation of it is already there.

Coursera
Coursera has been getting some real press these days. Started by a few Stanford Professors last year as a way to offer online courses from myriad universities for free, it has courses for credit and wide-ranging course offerings. In terms of computing, it has an Intro to Programing course from the University of Toronto, which is similar to what edX offers. However, Coursera offers other, more specialized code courses. I signed up to take a Social Networking Analysis course last year taught by a leading professor in that field.  Others include “Programming Languages” “Web Intelligence, and Big Data”.
Coursera is similar to edX in that courses are on a real schedule, with a curriculum, requiring a lot of your personal time. With both Coursera and edX you are taking a college-level course, that level of intellect is therefore required. In that regard it is leading the brigade in the thought that not only digital literacy is important, but that general education can be maintained through digital means. The onus is not necessarily that everyone needs to know coding, but that digital spaces can be used for positive, educational means.

P2PU
Mozilla has entered into the online courseware game with P2PU. In the tradition of Mozilla, P2PU is completely open, and provided a non-institutionalized, community-based education experience. It has a “School of Webcraft,” which includes “Webmaking 101” – a series of seven challenges aimed at teaching you how to start and code a blog.
The aim is less technical than, say, PHP Academy, and more community-oriented. Take, for instance, the first two challenges in “Webmaking 101.” In the first challenge you start a blog, introduce yourself to your peers, write a “magnificent blog post,” and link comments to your peers’ blogs. The second is to write simple HTML script by hand. There is a different emphasis than the rote skill-work taught in the other courses. Mozilla, in this regard, is working toward fostering a culture shift with digital literacy at the forefront.

Khan Academy
Khan Academy is, in some ways, an amalgam of Coursera and Codecademy. It claims to be working to change education “for the better by providing a free world-class education for anyone anywhere,” listing numerous subjects from computing to the humanities. The “Programming Basics” course has a similar format to Codecademy: read instructions and complete coding activities on a text screen to learn the necessary skills. Like Codecademy it progresses in a linear fashion toward mastering a basic repertoire. Khan has gotten scads of the press coverage, and I wouldn’t be surprised if it developed a more well-rounded curriculum around its original pedagogical style.

Codingbat
For a different approach there’s codingbat, which is simply a series of live coding problems. This site is tailored toward those with some previous knowledge of the subject, and has a bare bones interface pleasing to any hacker-in-training. The problems give immediate feedback to help improve skills, and were developed by Stanford CS lecturer, Nick Parlante. The two languages offered are Java and Python, and it now seems to be offering a theory course to teach skills in “small” coding so as to have the foundation to do longer pieces of code. The approach is educational at its core, but is difficult to delve in for the completely uninitiated.

GitHub, et. al.
Frequently coders refer me to GitHub, Pastebin, or SourceForge. These sites, like Codingbat, are not meant for the complete coding luddite and require an aptitude for “learning by doing”, and knowledge of how to navigate the confusing sitemap and specific terminology. There is no curriculum or series of online lectures. It is are a repository for coders to paste their personal code. Instead of a bottom-up pedagogy, these sites gives you successful codes from the best developers around. They are meant to foster community and keep collaborative efforts vibrant in the community. Friends of mine who code have told me that the best way to learn is to go on GitHub, study a cool code, and go from there. It is completely different than anything Coursera offers, and the end result, I think, is on the other end of the computing spectrum as well.

URL Rewriting for Beginners on Apache Serrver

Introduction

URL rewriting can be one of the best and quickest ways to improve the usability and search friendliness of your site. It can also be the source of near-unending misery and suffering. Definitely worth playing carefully with it - lots of testing is recommended. With great power comes great responsibility, and all that.
There are several other guides on the web already, that may suit your needs better than this one.
Before reading on, you may find it helpful to have the mod_rewrite cheat sheet and/or the regular expressions cheat sheet handy. A basic grasp of the concept of regular expressions would also be very helpful.

What is "URL Rewriting"?

Most dynamic sites include variables in their URLs that tell the site what information to show the user. Typically, this gives URLs like the following, telling the relevant script on a site to load product number 7.
http://www.pets.com/show_a_product.php?product_id=7 The problems with this kind of URL structure are that the URL is not at all memorable. It's difficult to read out over the phone (you'd be surprised how many people pass URLs this way). Search engines and users alike get no useful information about the content of a page from that URL. You can't tell from that URL that that page allows you to buy a Norwegian Blue Parrot (lovely plumage). It's a fairly standard URL - the sort you'd get by default from most CMSes. Compare that to this URL:
http://www.pets.com/products/7/ Clearly a much cleaner and shorter URL. It's much easier to remember, and vastly easier to read out. That said, it doesn't exactly tell anyone what it refers to. But we can do more:
http://www.pets.com/parrots/norwegian-blue/ Now we're getting somewhere. You can tell from the URL, even when it's taken out of context, what you're likely to find on that page. Search engines can split that URL into words (hyphens in URLs are treated as spaces by search engines, whereas underscores are not), and they can use that information to better determine the content of the page. It's an easy URL to remember and to pass to another person.
Unfortunately, the last URL cannot be easily understood by a server without some work on our part. When a request is made for that URL, the server needs to work out how to process that URL so that it knows what to send back to the user. URL rewriting is the technique used to "translate" a URL like the last one into something the server can understand.

Platforms and Tools

Depending on the software your server is running, you may already have access to URL rewriting modules. If not, most hosts will enable or install the relevant modules for you if you ask them very nicely.
Apache is the easiest system to get URL rewriting running on. It usually comes with its own built-in URL rewriting module, mod_rewrite, enabled, and working with mod_rewrite is as simple as uploading correctly formatted and named text files.
IIS, Microsoft's server software, doesn't include URL rewriting capability as standard, but there are add-ons out there that can provide this functionality. ISAPI_Rewrite is the one I recommend working with, as I've so far found it to be the closest to mod_rewrite's functionality. Instructions for installing and configuring ISAPI_Rewrite can be found at the end of this article.
The code that follows is based on URL rewriting using mod_rewrite.

Basic URL Rewriting

To begin with, let's consider a simple example. We have a website, and we have a single PHP script that serves a single page. Its URL is:
http://www.pets.com/pet_care_info_07_07_2008.php We want to clean up the URL, and our ideal URL would be:
http://www.pets.com/pet-care/ In order for this to work, we need to tell the server to internally redirect all requests for the URL "pet-care" to "pet_care_info_07_07_2008.php". We want this to happen internally, because we don't want the URL in the browser's address bar to change.
To accomplish this, we need to first create a text document called ".htaccess" to contain our rules. It must be named exactly that (not ".htaccess.txt" or "rules.htaccess"). This would be placed in the root directory of the server (the same folder as "pet_care_info_07_07_2008.php" in our example). There may already be an .htaccess file there, in which case we should edit that rather than overwrite it.
The .htaccess file is a configuration file for the server. If there are errors in the file, the server will display an error message (usually with an error code of "500"). If you are transferring the file to the server using FTP, you must make sure it is transferred using the ASCII mode, rather than BINARY. We use this file to perform 2 simple tasks in this instance - first, to tell Apache to turn on the rewrite engine, and second, to tell apache what rewriting rule we want it to use. We need to add the following to the file:
RewriteEngine On # Turn on the rewriting engine RewriteRule ^pet-care/?$ pet_care_info_01_02_2008.php [NC,L] # Handle requests for "pet-care" A couple of quick items to note - everything following a hash symbol in an .htaccess file is ignored as a comment, and I'd recommend you use comments liberally; and the "RewriteEngine" line should only be used once per .htaccess file (please note that I've not included this line from here onwards in code example).
The "RewriteRule" line is where the magic happens. The line can be broken down into 5 parts:
  • RewriteRule - Tells Apache that this like refers to a single RewriteRule.
  • ^/pet-care/?$ - The "pattern". The server will check the URL of every request to the site to see if this pattern matches. If it does, then Apache will swap the URL of the request for the "substitution" section that follows.
  • pet_care_info_01_02_2003.php - The "substitution". If the pattern above matches the request, Apache uses this URL instead of the requested URL.
  • [NC,L] - "Flags", that tell Apache how to apply the rule. In this case, we're using two flags. "NC", tells Apache that this rule should be case-insensitive, and "L" tells Apache not to process any more rules if this one is used.
  • # Handle requests for "pet-care" - Comment explaining what the rule does (optional but recommended)
The rule above is a simple method for rewriting a single URL, and is the basis for almost all URL rewriting rules.

Patterns and Replacements

The rule above allows you to redirect requests for a single URL, but the real power of mod_rewrite comes when you start to identify and rewrite groups of URLs based on patterns they contain.
Let's say you want to change all of your site URLs as described in the first pair of examples above. Your existing URLs look like this:
http://www.pets.com/show_a_product.php?product_id=7 And you want to change them to look like this:
http://www.pets.com/products/7/ Rather than write a rule for every single product ID, you of course would rather write one rule to manage all product IDs. Effectively you want to change URLs of this format:
http://www.pets.com/show_a_product.php?product_id={a number} And you want to change them to look like this:
http://www.pets.com/products/{a number}/ In order to do so, you will need to use "regular expressions". These are patterns, defined in a specific format that the server can understand and handle appropriately. A typical pattern to identify a number would look like this:
[0-9]+ The square brackets contain a range of characters, and "0-9" indicates all the digits. The plus symbol indicates that the pattern will idenfiy one or more of whatever precedes the plus - so this pattern effectively means "one or more digits" - exactly what we're looking to find in our URL.
The entire "pattern" part of the rule is treated as a regular expression by default - you don't need to turn this on or activate it at all.
RewriteRule ^products/([0-9]+)/?$ show_a_product.php?product_id=$1 [NC,L] # Handle product requests The first thing I hope you'll notice is that we've wrapped our pattern in brackets. This allows us to "back-reference" (refer back to) that section of the URL in the following "substitution" section. The "$1" in the substitution tells Apache to put whatever matched the earlier bracketed pattern into the URL at this point. You can have lots of backreferences, and they are numbered in the order they appear.
And so, this RewriteRule will now mean that Apache redirects all requests for domain.com/products/{number}/ to show_a_product.php?product_id={same number}.

Regular Expressions

A complete guide to regular expressions is rather beyond the scope of this article. However, important points to remember are that the entire pattern is treated as a regular expression, so always be careful of characters that are "special" characters in regular expressions.
The most instance of this is when people use a period in their pattern. In a pattern, this actually means "any character" rather than a literal period, and so if you want to match a period (and only a period) you will need to "escape" the character - precede it with another special character, a backslash, that tells Apache to take the next character to be literal.
For example, this RewriteRule will not just match the URL "rss.xml" as intended - it will also match "rss1xml", "rss-xml" and so on.
RewriteRule ^rss.xml$ rss.php [NC,L] # Change feed URL This does not usually present a serious problem, but escaping characters properly is a very good habit to get into early. Here's how it should look:
RewriteRule ^rss\.xml$ rss.php [NC,L] # Change feed URL This only applies to the pattern, not to the substitution. Other characters that require escaping (referred to as "metacharacters") follow, with their meaning in brackets afterwards:
  • . (any character)
  • * (zero of more of the preceding)
  • + (one or more of the preceding)
  • {} (minimum to maximum quantifier)
  • ? (ungreedy modifier)
  • ! (at start of string means "negative pattern")
  • ^ (start of string, or "negative" if at the start of a range)
  • $ (end of string)
  • [] (match any of contents)
  • - (range if used between square brackets)
  • () (group, backreferenced group)
  • | (alternative, or)
  • \ (the escape character itself)
Using regular expressions, it is possible to search for all sorts of patterns in URLs and rewrite them when they match. Time for another example - we wanted earlier to be able to indentify this URL and rewrite it:
http://www.pets.com/parrots/norwegian-blue/
And we want to be able to tell the server to interpret this as the following, but for all products:
http://www.pets.com/get_product_by_name.php?product_name=norwegian-blue And we can do that relatively simply, with the following rule:
RewriteRule ^parrots/([A-Za-z0-9-]+)/?$ get_product_by_name.php?product_name=$1 [NC,L] # Process parrots With this rule, any URL that starts with "parrots" followed by a slash (parrots/), then one or more (+) of any combination of letters, numbers and hyphens ([A-Za-z0-9-]) (note the hyphen at the end of the selection of characters within square brackets - it must be added there to be treated literally rather than as a range separator). We reference the product name in brackets with $1 in the substitution.
We can make it even more generic, if we want, so that it doesn't matter what directory a product appears to be in, it is still sent to the same script, like so:
RewriteRule ^[A-Za-z-]+/([A-Za-z0-9-]+)/?$ get_product_by_name.php?product_name=$1 [NC,L] # Process all products As you can see, we've replaced "parrots" with a pattern that matches letter and hyphens. That rule will now match anything in the parrots directory or any other directory whose name is comprised of at least one or more letters and hyphens.

Flags

Flags are added to the end of a rewrite rule to tell Apache how to interpret and handle the rule. They can be used to tell apache to treat the rule as case-insensitive, to stop processing rules if the current one matches, or a variety of other options. They are comma-separated, and contained in square brackets. Here's a list of the flags, with their meanings (this information is included on the cheat sheet, so no need to try to learn them all).
  • C (chained with next rule)
  • CO=cookie (set specified cookie)
  • E=var:value (set environment variable var to value)
  • F (forbidden - sends a 403 header to the user)
  • G (gone - no longer exists)
  • H=handler (set handler)
  • L (last - stop processing rules)
  • N (next - continue processing rules)
  • NC (case insensitive)
  • NE (do not escape special URL characters in output)
  • NS (ignore this rule if the request is a subrequest)
  • P (proxy - i.e., apache should grab the remote content specified in the substitution section and return it)
  • PT (pass through - use when processing URLs with additional handlers, e.g., mod_alias)
  • R (temporary redirect to new URL)
  • R=301 (permanent redirect to new URL)
  • QSA (append query string from request to substituted URL)
  • S=x (skip next x rules)
  • T=mime-type (force specified mime type)

Moving Content

RewriteRule ^article/?$ http://www.new-domain.com/article/ [R,NC,L] # Temporary Move Adding an "R" flag to the flags section changes how a RewriteRule works. Instead of rewriting the URL internally, Apache will send a message back to the browser (an HTTP header) to tell it that the document has moved temporarily to the URL given in the "substitution" section. Either an absolute or a relative URL can be given in the substitution section. The header sent back includea a code - 302 - that indicates the move is temporary.
RewriteRule ^article/?$ http://www.new-domain.com/article/ [R=301,NC,L] # Permanent Move If the move is permanent, append "=301" to the "R" flag to have Apache tell the browser the move is considered permanent. Unlike the default "R", "R=301" will also tell the browser to display the new address in the address bar.
This is one of the most common methods of rewriting URLs of items that have moved to a new URL (for example, it is in use extensively on this site to forward users to new post URLs whenever they are changed).

Conditions

Rewrite rules can be preceded by one or more rewrite conditions, and these can be strung together. This can allow you to only apply certain rules to a subset of requests. Personally, I use this most often when applying rules to a subdomain or alternative domain as rewrite conditions can be run against a variety of criteria, not just the URL. Here's an example:
RewriteCond %{HTTP_HOST} ^addedbytes\.com [NC] RewriteRule ^(.*)$ http://www.addedbytes.com/$1 [L,R=301] The rewrite rule above redirects all requests, no matter what for, to the same URL at "www.addedbytes.com". Without the condition, this rule would create a loop, with every request matching that rule and being sent back to itself. The rule is intended to only redirect requests missing the "www" URL portion, though, and the condition preceding the rule ensures that this happens.
The condition operates in a similar way to the rule. It starts with "RewriteCond" to tell mod_rewrite this line refers to a condition. Following that is what should actually be tested, and then the pattern to test. Finally, the flags in square brackets, the same as with a RewriteRule.
The string to test (the second part of the condition) can be a variety of different things. You can test the domain being requested, as with the above example, or you could test the browser being used, the referring URL (commonly used to prevent hotlinking), the user's IP address, or a variety of other things (see the "server variables" section for an outline of how these work).
The pattern is almost exactly the same as that used in a RewriteRule, with a couple of small exceptions. The pattern may not be interpreted as a pattern if it starts with specific characters as described in the following "exceptions" section. This means that if you wish to use a regular expression pattern starting with <, >, or a hyphen, you should escape them with the backslash.
Rewrite conditions can, like rewrite rules, be followed by flags, and there are only two. "NC", as with rules, tells Apache to treat the condition as case-insensitive. The other available flag is "OR". If you only want to apply a rule if one of two conditions match, rather than repeat the rule, add the "OR" flag to the first condition, and if either match then the following rule will be applied. The default behaviour, if a rule is preceded by multiple conditions, is that it is only applied if all rules match.

Exceptions and Special Cases

Rewrite conditions can be tested in a few different ways - they do not need to be treated as regular expression patterns, although this is the most common way they are used. Here are the various ways rewrite conditons can be processed:
  • <Pattern (is test string lower than pattern)
  • >Pattern (is test string greater than pattern)
  • =Pattern (is test string equal to pattern)
  • -d (is test string a valid directory)
  • -f (is test string a valid file)
  • -s (is test string a valid file with size greater than zero)
  • -l (is test string a symbolic link)
  • -F (is test string a valid file, and accessible (via subrequest))
  • -U (is test string a valid URL, and accessible (via subrequest))

Server Variables

Server variables are a selection of items you can test when writing rewrite conditions. This allows you to apply rules based on all sorts of request parameters, including browser identifiers, referring URL or a multitude of other strings. Variables are of the following format:
%{VARIABLE_NAME} And "VARIABLE_NAME" can be replaced with any one of the following items:
  • HTTP Headers
    • HTTP_USER_AGENT
    • HTTP_REFERER
    • HTTP_COOKIE
    • HTTP_FORWARDED
    • HTTP_HOST
    • HTTP_PROXY_CONNECTION
    • HTTP_ACCEPT
  • Connection Variables
    • REMOTE_ADDR
    • REMOTE_HOST
    • REMOTE_USER
    • REMOTE_IDENT
    • REQUEST_METHOD
    • SCRIPT_FILENAME
    • PATH_INFO
    • QUERY_STRING
    • AUTH_TYPE
  • Server Variables
    • DOCUMENT_ROOT
    • SERVER_ADMIN
    • SERVER_NAME
    • SERVER_ADDR
    • SERVER_PORT
    • SERVER_PROTOCOL
    • SERVER_SOFTWARE
  • Dates and Times
    • TIME_YEAR
    • TIME_MON
    • TIME_DAY
    • TIME_HOUR
    • TIME_MIN
    • TIME_SEC
    • TIME_WDAY
    • TIME
  • Special Items
    • API_VERSION
    • THE_REQUEST
    • REQUEST_URI
    • REQUEST_FILENAME
    • IS_SUBREQ

Working With Multiple Rules

The more complicated a site, the more complicated the set of rules governing it can be. This can be problematic when it comes to resolving conflicts between rules. You will find this issue rears its ugly head most often when you add a new rule to a file, and it doesn't work. What you may find, if the rule itself is not at fault, is that an earlier rule in the file is matching the URL and so the URL is not being tested against the new rule you've just added.
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ get_product_by_name.php?category_name=$1&product_name=$2 [NC,L] # Process product requests RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ get_blog_post_by_title.php?category_name=$1&post_title=$2 [NC,L] # Process blog posts In the example above, the product pages of a site and the blog post pages have identical patterns. The second rule will never match a URL, because anything that would match that pattern will have already been matched by the first rule.
There are a few ways to work around this. Several CMSes (including wordpress) handle this by adding an extra portion to the URL to denote the type of request, like so:
RewriteRule ^products/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ get_product_by_name.php?category_name=$1&product_name=$2 [NC,L] # Process product requests RewriteRule ^blog/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ get_blog_post_by_title.php?category_name=$1&post_title=$2 [NC,L] # Process blog posts You could also write a single PHP script to process all requests, which checked to see if the second part of the URL matched a blog post or a product. I usually go for this option, as while it may increase the load on the server slightly, it gives much cleaner URLs.
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ get_product_or_blog_post.php?category_name=$1&item_name=$2 [NC,L] # Process product and blog requests There are certain situations where you can work around this issue by writing more precise rules and ordering your rules intelligently. Imagine a blog where there were two archives - one by topic and one by year.
RewriteRule ^([A-Za-z0-9-]+)/?$ get_archives_by_topic.php?topic_name=$1 [NC,L] # Get archive by topic RewriteRule ^([A-Za-z0-9-]+)/?$ get_archives_by_year.php?year=$1 [NC,L] # Get archive by year The above rules will conflict. Of course, years are numeric and only 4 digits, so you can make that rule more precise, and by running it first the only type of conflict you cound encounter would be if you had a topic with a 4-digit number for a name.
RewriteRule ^([0-9]{4})/?$ get_archives_by_year.php?year=$1 [NC,L] # Get archive by year RewriteRule ^([A-Za-z0-9-]+)/?$ get_archives_by_topic.php?topic_name=$1 [NC,L] # Get archive by topic

mod_rewrite

Apache's mod_rewrite comes as standard with most Apache hosting accounts, so if you're on shared hosting, you are unlikely to have to do anything. If you're managing your own box, then you most likely just have to turn on mod_rewrite. If you are using Apache1, you will need to edit your httpd.conf file and remove the leading '#' from the following lines:
#LoadModule rewrite_module modules/mod_rewrite.so #AddModule mod_rewrite.c If you are using Apache2 on a Debian-based distribution, you need to run the following command and then restart Apache:
sudo a2enmod rewrite Other distubutions and platforms differ. If the above instructions are not suitable for your system, then Google is your friend. You may need to edit your apache2 configuration file and add "rewrite" to the "APACHE_MODULES" list, or edit httpd.conf, or even download and compile mod_rewrite yourself. For the majority, however, installation should be simple.

ISAPI_Rewrite

ISAPI_Rewrite is a URL rewriting plugin for IIS based on mod_rewrite and is not free. It performs most of the same functionality as mod_rewrite, and there is a good quality ISAPI_Rewrite forum where most common questions are answered. As ISAPI_Rewrite works with IIS, installation is relatively simple - there are installation instructions available.
ISAPI_Rewrite rules go into a file named httpd.ini. Errors will go into a file named httpd.parse.errors by default.

Leading Slashes

I have found myself tripped up numerous times by leading slashes in URL rewriting systems. Whether they should be used in the pattern or in the substitution section of a RewriteRule or used in a RewriteCond statement is a constant source of frustration to me. This may be in part because I work with different URL rewriting engines, but I would advise being careful of leading slashes - if a rule is not working, that's often a good place to start looking. I never include leading slashes in mod_rewrite rules and always include them in ISAPI_Rewrite.

Sample Rules

To redirect an old domain to a new domain:
RewriteCond %{HTTP_HOST} old_domain\.com [NC] RewriteRule ^(.*)$ http://www.new_domain.com/$1 [L,R=301] To redirect all requests missing "www" (yes www):
RewriteCond %{HTTP_HOST} ^domain\.com [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] To redirect all requests with "www" (no www):
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC] RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301] Redirect old page to new page:
RewriteRule ^old-url\.htm$ http://www.domain.com/new-url.htm [NC,R=301,L]

Useful Links

Summary

Hopefully if you've made it this far you now have a clear understanding of what URL rewriting is and how to add it to your site. It is worth taking the time to become familiar with - it can benefit your SEO efforts immediately, and increase the usability of your site.