Hi guys. I’ve spent the last few hours trying to get my head around this problem. I’ve got a site using some translation software and it works for the most part but it cannot work in the checkout stages so I want to redirect the url it’s creating www.mysite.com/nl/index.php?etc to www.mysite.com/index.php?etc
I’ve been trying different combinations of things but I simply don’t have the experience with mod rewrite, if anyone could point me in the right direction, I’d greatly appreciate it. Thanks for your time. Ant.
Second, it would help if you’d read the mod_rewrite tutorial linked in my signature. It develops the regex you need to convert from one server/path/file to another and then provides a lot of explained examples.
Third, I’ll guess that you entered full links but the forum software shortened them and that information is lost - not that it seems that it would make much difference. Wrapping code (and URLs) in [noparse]
...
[/noparse] would preserve EVERYTHING between the brackets.
Fourth, “specificity” is important in letting someone else know what you’re attempting so let me give you a start:
nl/index.php?{query_string} => index.php?{query_string} is merely a directory change (code in the tutorial) and the query string is NOT affected by the redirection UNLESS you add/modify the query string with the redirection. The ja directory would get the same treatment.
Please give it a try then share your code and level of success. Don’t worry, we’ll get you where you want (but I treat this board as a learning tool, not for free coding).
Now I know that works and picks up the query string and redirects the URL to the same URL. It’s just I want to specify that there has to be a nl/ ja/ de/ preceding the index.php? and I’m no sure how to do that, even after reading the tutorial. I don’t understand what you mean by “give that a try”. Are you saying that I can use:
How do I specify the query_string to use? would this work:
RewriteRule ^nl/index.php?{page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65} => index.php?{page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65}[R=301]
A RewriteRule can NOT examine anything other than the {REQUEST_URI} so any attempt to do so will result in an error (incorrect regex): The ? is a metacharacter which means “zero or one” of the preceding character and curly braces are not allowed but, if they were, you’d have to have {query_string} in your URI - I’d used {query_string} as a place holder.
RewriteRule format is “RewriteRule” followed by a single space followed by “regex” followed by a single space followed by “the redirection” optionally followed by a single space and square bracketed flags (without ANY MORE SPACES). Obviously, do NOT include the quotes!
As explained above, you do not need to concern yourself with the query string if you mean to retain it. Otherwise, you MUST use a RewriteCond statement to view the {QUERY_STRING} variable. If your redirection was to change the query string in any way, you would likely use this to capture values for the redirection.
Try it meant to use:
RewriteRule ^nl/index\\.php$ index.php [R=301,L]
Oh, you were SO close (but didn’t read the tutorial with comprehension). Questions?
Not work, because it would direct any instance of /nl/index.php followed by any string to the second URL. I only want the URL redirecting if the string is
IF you want the redirection only for Itemid=65 (the entire query string - even the duplicated &Itemid=65), then, by all means, precede the RewriteRule with
This is completely perfect, the only problem is it’s in reverse. I just can’t figure that part out I need that URL with the nl/ prefix to redirect to the URL without the prefix. Any ideas would be much appreciated. Thanks all.
And that is changing the specification on us! For shame! Okay, that’s a noobie mistake thinking that mod_rewrite will redirect to the NEW format.
If you’ll tell us what you REALLY want, we can help you get through the mod_rewrite. Of course, you’ll need to be sure that all the pieces are in the specification so the redirection makes sense.
The code above used your “weird” query string (Itemid=65&redirected=1&Itemid=54) does exactly that! It matches your query string then, if the URI is index.php, performs the redirection to eliminate the nl subdirectory.
Your code, however,
RewriteCond %{HTTP_HOST} ^www.seed-city.com
[indent]AGAIN, ESCAPE the dot characters, end the string and use the No Case flag![/indent]
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65
[indent]Only one Itemid=65 and no redirection=1?[/indent]
RewriteRule ^[COLOR="Red"](.*)[/COLOR]$[COLOR="Gray"] http://www.seed-city.com/[/COLOR]nl/index.php?page=checkout.index&option=com_virtuemart&Itemid=65 [R=301]
[indent]Redirect EVERYTHING? Redirect NOTHING?
Making an external (absolute) redirect? Why? That's only necessary if not at the same {HTTP_HOST} (which you've required in the RewriteCond).
Changing the query string, too? PLEASE check your specification as the query string you've insisted upon is the crux of this matter.[/indent]
UNLESS you’re trying to redirect TO the nl subdirectory?
But redirecting TO nl/ is NOT what you’ve requested, is it?
The problem seems to be that it’s not picking up the nl/index part of the rewrite rule. If I remove nl/ the redirection will work but with the nl/ in place it’s not picking it up. Any help would be much appreciated. Thanks, Ant. Could it be a problem that the URL is dynamically generated and there is no existing nl folder?
Would you PLEASE address the duplicated Itemid=65 in your query string? Is this whole thing generated? Generated as “page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65”? I feel that we’re not going anywhere with this without confirmation of this “ridiculous” query string which you’ve stated is the ONLY thing that needs to be matched to be redirected.
Then, does the generated link include the nl subdirectory? If not, then the code is working as intended (as specified, anyway).
However, it doesn’t. The nl/ part of the URL is also generated as no NL directory exists. It’s a part of a translation extension and creates subfolders for different languages nl/ ja/ de/ etc. Thanks, Ant.
I still can’t figure out why nl/index.php won’t work. I guess it must be because the nl/ part of the URL is dynamically generated as well. Do you know how I could specify that the URL has two dynamic parts? Thanks for your time. Ant.
Would you PLEASE address the duplicated Itemid=65 in your query string? Is this whole thing generated? Generated as “page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=6 5”? I feel that we’re not going anywhere with this without confirmation of this “ridiculous” query string which you’ve stated is the ONLY thing that needs to be matched to be redirected.
Then, does the generated link include the nl subdirectory? If not, then the code is working as intended (as specified, anyway).
I don’t understand the specificity you’re after. I want to turn one URL into another. Please specify the specifics you want. Thanks for your time. Ant.