Forum Moderators: phranque
old
index.php?automodule=downloads
index.php?autocom=downloads
new
index.php?app=downloads
there are lots of dynamic url's though like
index.php?automodule=downloads&showcat=4
index.php?automodule=downloads&showfile=84
any ideas to try welcome and much appreciated.
If "automodule=" and "autocom=" are always the first query parameters, then this is easy. If not, you'll need at least two RewriteConds to detect three cases: "automodule=" and "autocom=" at the beginning, "automodule=" and "autocom=" in the middle, and "automodule=" and "autocom=" at the end of the query string (If these query names are missing altogether, then none of these conditions will be met and the rule won't be invoked, so you don't need an explicit test for that case.) In practical terms, this can usually be accomplished with two RewriteConds.
Try searching WebmasterWorld (see "Search" link a top of this page) for "RewriteCond %{QUERY_STRING} RewriteRule" to turn up previous threads on this subject, take a look at the resources cited in our Apache Forum Charter and Library, and then post your best-effort at a coded solution as a basis for discussion.
Thanks,
Jim
With a redirect you should also specify the domain name in the target.
If you want a rewrite omit both the domain name and the [R=301] too.
QUERY_STRING can see ONLY the query string data, not any path part information.
RewriteRule needs both a pattern (to match the part-part of the requested URL) and a target. You have omitted one of those parts.
You've got a bit of a mix-up of what's in the URL-path and what's in the query string appended to that URL-path, and there's no provision to 'keep' any other parts of the query string if they're present. Also, characters which have meaning as regular-expressions tokens must be escaped if you wish to match them as literal characters within a pattern (e.g a period is a regex token which matches any single character). Finally, it's a very good idea to specify a full canonical URL in the RewriteRule substitution to avoid problems under certain server configurations.
So this will likely work better:
RewriteCond %{QUERY_STRING} ^auto(module¦com)=downloads((&.+)¦&)?$
RewriteRule ^board/index\.php$ http://example.com/board/index.php?app=downloads%3 [R=301,L]
Here "%3" in the substitution URL back-references (refers back to) to the matched contents of the third parenthesized sub-pattern in the RewriteCond, allowing any additional name-value pairs in the query string to be retained in the new URL. The rule will be invoked whether or not these additional parameters are present, because the entire second subpattern (and the third within it) is made entirely optional by the "?" following the parentheses.
Note also that I have replicated the "/board" URL-path-part that you put in your code although you didn't mention in your original post. So this code will work on requests for "example.com/board/index.php" assuming that this code is located in example.com/.htaccess.
Jim
So it works perfect now, I've got a way to go to get my head around this and my hat goes of to you Jim, you certainly know your stuff. Thank You for your help.
^auto(module¦com)=downloads((&.+)¦&)?$
If the query string starts with "auto", followed by "module" or "com", followed by "=downloads", followed by "&" and then anything else or just "&", then copy the "& and anything else" into %3 and invoke the rule. If the "ampersand and anything else" in %3 is blank, so be it. If there was just an ampersand after "=download", then drop it and don't copy it into the new query string. This latter feature is intended to prevent duplicate-content problems where you could end up with both "index.php?app=download" and "index.php?app=download&" URLs, due to either your own linking mistakes or the mistakes of others linking to you. Both of these URL variants would work, but likely return the same content, and that could potentially cause you "duplicate-content" trouble in search engine ranking. So all the 'fancy nested parenthetical constructs' are intended to copy the additional query parameters but drop empty ones.
You could also write it as:
RewriteCond %{QUERY_STRING} ^auto(module¦com)=downloads((&[^&]+)*)&?$
RewriteRule ^board/index\.php$ http://example.com/board/index.php?app=download[b]s%2[/b] [R=301,L]
As before, replace the broken pipe character...
Jim