lucy24 - 1:00 am on Jul 27, 2013 (gmt 0)
Especially becuase I want to learn it good.To know syntax and the use of everything.Becuase if I don't know it there is no use.
Keep saying this periodically. It makes people happy, and happy people are more willing to help :)
Let me try a different way to explain redirect vs. rewrite.
You send your browser to the store. It finds a sign on the door that says "This entrance no longer in use. Go around to the 12th Street side." So the browser has to try a different door. Meanwhile you-- the human-- are waiting in the car. You might not even know that the browser has gone to a different door, unless you happen to look up and see it turning the corner.
Browser comes to the (correct) door and says "I need a gallon of milk. It's in the aisle to the left." Clerk says "You betcha!", ducks into the specified aisle-- and then runs over to a completely different part of the store and comes back with the milk. "Here it is, just where you said."
If you are doing the full redirect-to-rewrite two-step, the milk may actually be located just inside the old door-- the one the browser is no longer allowed to use. But neither you nor the browser knows this.
Now then: The element /localhost/ is not part of the URL path. IGNORE IT, in the same way that you would omit www.example.com on your real site.
In htaccess*, a mod_rewrite pattern begins with the first directory after the domain name. (It may even begin later, if there's no anchor-- or if the htaccess file is located in a deeper directory. But the first directory is the earliest a pattern can ever begin.)
A mod_rewrite target can technically begin in any of three ways:
#1 text without slash
This form is rarely if ever necessary or appropriate, so let's scratch that right away.
#2 http://www.example.com/ where http (or https) is your desired protocol and example.com is any hostname including localhost:some-number-here
When you are testing locally, you could give the full http://localhost:8888 or whatever. But there's no reason to. There's no possibility of giving the wrong form of the hostname; you're obviously not being indexed, so Duplicate Content is not an issue; and https may not even be supported. (I just tried it in MAMP. Browser said nuh-uh, no go. Maybe if I change the default settings, or upgrade to the paid version.) And no matter what you say, you'll have to edit the target for the htaccess of your real site.
What you do need to include in all local testing is the [R=301] flag, because otherwise mod_rewrite won't know that you are redirecting.
#3 / (leading slash, meaning start from the root of your current domain-- no matter where the htaccess file is physically located)
When you are testing with localhost, all RewriteRules will have targets in this form. On your live site, it is only used for internal rewrites. That means the rules with [L] flag only.
* Also in <Directory> sections within the config file, but never mind that now. In htaccess you can't make a <Directory> section.