I need to do the following redirection:
FROM:
https://www.example.com/?s=busqueda
TO:
https://www.example.com/?s=busqueda&post_type=product&dgwt_wcas=1
I tried with:
RewriteCond% {QUERY_STRING} s = (.*)
RewriteRule ^ $?S=%1&post_type=product&dgwt_wcas=1[NE]
But it does not work! If anyone has any idea why, I appreciate the explanation :)
(I assume the double slash at the start of the URL-path in the destination URL is a typo?)
Try the following near the top of the .htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(s=busqueda)$
RewriteRule ^$ /?%1&post_type=product&dgwt_wcas=1 [R=302,L]
It looks like you were probably quite close in your attempt, however, since you were missing start/end anchors (^ and $) on the CondPattern when matching the query string it would have resulted in a redirect/rewrite loop.
The directive you posted is also a rewrite, not a "redirect" as you stated in your question.
Related
How to redirect https://www.themaidsofcharleston.com/?Itemid= to https://www.themaidsofcharleston.com/
I have tried
RewriteCond %{QUERY_STRING} ^?Itemid=$
RewriteRule ^/$ /? [R=301,L]
but id doesn't work
Thank you in advance.
Two issues needed fixing here:
{QUERY_STRING} does not contain the leading question mark - you want to check for ^Itemid=$
when configuring rewriting in .htaccess context, the path never starts with a /, that has been stripped off at that point already. So your rule needs to match an empty path instead, ^$
I made a mistake in creating links. I corrected it but now still there are links floating around that might look like this:
http://www.domain.com/?page=1?date=29062015&id=778
I would like to correct this using the rewriteEngine to redirect my users to:
http://www.domain.com/?page=1&date=29062015&id=778
I searched around and tried the following, but it doesn't work:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)\?(.*)$
RewriteRule ^\/ ^\/$1\&$2 [L,R=301]
What should I change here?
I've slightly corrected your rule,hope it will help to resolve the issue:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)\?(.*)$
RewriteRule (.*) $1?%1&%2 [L,R=301]
Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond (Query string condition).
Good article about rewriting query string here: https://wiki.apache.org/httpd/RewriteQueryString
I'm struggling with an Apache rewriterule. I need to do the following:
Redirect permanently:
http://domain.com/folder/viewer/data/settings.xml?prevent_cache=4760
to
http://domain.com/siteid/includes/themes/siteid/swfs/viewer/data/settings.xml?prevent_cache=4760
I've got the code below, it works without the url parameters but I can't seem to get it to work with parameters. Am i missing something?
RewriteCond %{QUERY_STRING} ^prevent_cache=([0-9]*)$
RewriteRule ^/folder/viewer/data/settings.xml$ http://domain.com/siteid/includes/themes/siteid/swfs/viewer/data/settings.xml [R=301,L]
Cheers
Shaun
The only error I can see, is the leading slash / in the RewriteRule pattern. This should be
RewriteCond %{QUERY_STRING} ^prevent_cache=[0-9]*$
RewriteRule ^folder/viewer/data/settings.xml$ /siteid/includes/themes/siteid/swfs/viewer/data/settings.xml [R,L]
You don't need to append the query string to the substitution URL, because this is done autmoatically.
When everything works as you expect, you can change R to R=301. Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.
I can. Here are the rewrite condition and rule that you're looking for:
# once per htaccess file
RewriteEngine on
RewriteCond %{QUERY_STRING} prevent_cache=([0-9]*)
RewriteRule ^folder/viewer/data/settings.xml http://domain.com/siteid/includes/themes/siteid/swfs/viewer/data/settings.xml?prevent_cache=%1 [R=301,L]
But please considered this answer about the [R=301] flag: https://stackoverflow.com/a/15999177/2007055
I have these links in my website:
www.example.org/folder/files.php?file=folder/document.pdf
www.example.org/folder/files.php?force&file=2009.pdf
and I want redirect to :
www.example.org/files/folder/document.pdf
www.example.org/files/2009.pdf
I tried :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^files/(.*)$ /files.php?file=$1 [R=301,L]
</IfModule>
but doesn't work!
any help?
RewriteRule ^files/(.*)$ /files.php?file=$1 [R=301,L]
There are two issues with this rule ... first, what you are matching needs to appear first in the rule, then what you are rewriting appears second - you have that backwards.
Once you reverse that, though, you run into the second issue - you can't match query strings in a RewriteRule, you need to match them in a RewriteCond:
To match www.example.org/folder/files.php?force&file=2009.pdf and redirect it to www.example.org/files/2009.pdf you would do:
RewriteCond %{QUERY_STRING} ^force&file=(.*)$ [NC]
RewriteRule ^folder/files.php$ /files/%1 [R=301, L]
The %1 matches what's in the parentheses in the RewriteCond.
Search on google first. The first thing displayed on google for htaccess is htaccess redirect. I think
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html (same line with a space) should work. Go to http://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F . Php would also do the work. Just goolgle things before asking them.
I'm trying to come up with some mod_rewrite to translate http://example.com/?7gudznrxdnu into http://example.com/view.php?id=7gudznrxdnu
But any other page will function properly such as http://example.com/contact and so on.
I think this will work:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^[a-z0-9]+$
RewriteRule ^$ view.php?id=%{QUERY_STRING} [L]
If you want the rewrite to be shown in the browser's address field, you'll have to replace [L] with [L,R=301].
Explanation: The query-string (what's following the question mark) is not part of the URL that RewriteRule sees in its matching-pattern, therefore you can't check for question mark there. In my solution, I run the rule if and only if (RewriteCond) the query string consists solely of a-z and/or 0-9, and my rule only rewrites URLs ending with a slash (except for the query string). I redirect this to view.php?id=, and then append the query string to that.
Edit: Tested on my Apache-server, and I haven't found any bugs (yet).
You should try (in your .htaccess):
RewriteEngine On
RewriteRule ^\?([^/\.]+)?$ view.php?id=$1 [L]