| 6:03 am on Jul 8, 2012 (gmt 0)|
RewriteRule ^/?$ "http\:\/\/www\.example\.com" [R=301,L]
Redirects works fine if i use http://example.com which redirects it to http://www.example.com but when i use some inner page as
then i want it to be redirected to http://www.example.com/results/?type1=&type2=&type3=&price=&x=31&y=7&flag=
For any http:// URL it should be redirected to http://www to avoid URLs duplication.
[edited by: incrediBILL at 7:44 am (utc) on Jul 8, 2012]
[edit reason] fixed formatting [/edit]
| 7:36 am on Jul 8, 2012 (gmt 0)|
Uhm... Your question reads as if it's a continuation from an ongoing thread. I don't think it really is. But I think you've become so absorbed in the problem that you forget we're hearing about it for the first time.
In English: What are you trying to do? At a guess, you want to redirect everyone to the canonical version of your site name-- with or without www-- but I'm not betting money on it.
Before you answer, read the post at the top of this Forum about using example.com. Matter of fact, read some random other posts and you may never need to come back at all. This is an amazingly repetive Forum. Maybe something about Apache makes people afraid to look at other people's questions even if they seem to be identical.
In mod_rewrite you do not need to escape / slashes. As far as I know, you never need to escape colons anywhere. You do need to escape literal periods. BUT you do not need to escape anything at all, whatsoever, of any kind, in the target (the part on the right).
Now, about that mile-long query string that you haven't even mentioned... ;)
| 8:01 am on Jul 8, 2012 (gmt 0)|
Thanks for the reply.
|In English: What are you trying to do? At a guess, you want to redirect everyone to the canonical version of your site name-- with or without www-- but I'm not betting money on it. |
I want all of my non www urls to be redirected to www urls to avoid duplication.
| 9:41 am on Jul 8, 2012 (gmt 0)|
^/?$ matches requests for example.com/ and for example.com// only, so no inner pages will ever be affected by this rule.
You'll need (.*) to match all pages.
You'll also need a RewriteCond testing that the requested hostname was not "exactly" www.example.com
Escaping should not be used in the rule target, nor should quotes.
Check recent threads for example code. This is a question covered several times each month.
| 10:52 am on Jul 8, 2012 (gmt 0)|
|Redirects works fine if i use http://example.com which redirects it to http://www.example.com |
Ah, but what if you had said www.example.com in the first place? You would still be redirected, and the request would go around in circles until the user's browser (not your server) put a stop to it.
General rule: When testing something, don't only test it on things that are supposed to work. Also test it on things that are not supposed to work-- or that are supposed to not work, depending on how you look at it. And test it on garbage to make sure it's GIGO. (This is what is supposed to happen.)
Here you need a RewriteCond to ensure that only the right things-- er, that is, the wrong things-- get redirected. Exact wording will be found in many many threads in this forum. Conceptually what you need to say is: "If the requested host is NOT exactly such-and-such, then redirect to such-and-such".
As Tolstoy said: correct URLs are all alike. Incorrect URLs are each incorrect in their own way.