I'd like to append '?OpenBox=1' to example.com/de/Kontakt, so in the end it should look like this:
example.com/de/Kontakt?OpenBox=1
I initially tried to do this using a permanent rewrite:
RedirectPermanent ^de/Kontakt https://www.example.com/de/Kontakt?OpenBox=1
But apparently this ends up in a loop.
I checked the solution from here htaccess Rewrite Rules appending parameter?
RewriteEngine On
RewriteCond %{QUERY_STRING} ^/Kontakt$ [NC]
RewriteRule ^$ /?OpenBox=1 [R=301,L]
But this doesnt seem to do anything.
What am I missing? Thanks, Nouny
Related
I used to have a link like:
www.domain.com/index.php?id=IdParameter&place=true
But I don't use "place=true" anymore.
I want all those links to look like:
www.domain.com/index.php?id=IdParameter
WITHOUT the "&place=true" part.
How can I redirect links including "place=true" to themselves, without that last part?
thanks
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.+?)&place=true$ [NC]
RewriteRule ^index\.php$ %{REQUEST_URI}?%1 [L,R]
I'm having some trouble using the right code for my .htaccess file.
What I'm trying to accomplish is this:
We have a QR code generator which generates random url'Ss like this:
http://mydomain.com?APP-V2/7091c104-32a8-4680-9c07-a75c3ee61d7a/00
I need to redirect all these url's to the homepage, http://mydomain.com.
How to I write the wildcard in my htaccess file? Basically everything after mydomain.com?APP-V2/ should be redirected.
Any help much appreciated!
Basically everything after mydomain.com?APP-V2/ should be redirected.
If you want:
http://mydomain.com/?APP-V2/7091c104-32a8-4680-9c07-a75c3ee61d7a/00
to be redirected to:
http://mydomain.com/
Then you just get rid of the query string (e.g. ?APP-V2/7091c104-32a8-4680-9c07-a75c3ee61d7a/00):
RewriteEngine On
RewriteCond %{QUERY_STRING} ^APP-V2/
RewriteRule ^$ /? [L]
But if you want everything after the ?APP-V2/, you need this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^APP-V2/(.*)$
RewriteRule ^$ /%1? [L]
I've been trying to rewrite a URL such as
www.somesite.com/?x=372
into a url
www.somesite.com/
My current code does not seem to work
RewriteEngine On
RewriteCond %{QUERY_STRING} x=(.*)
RewriteRule http://www.somesite.com/ [R=301,L]
I've looked up countless ways of trying to do it with htaccess and still no success.
If you simply want to redirect a client to remove the query string (everything after the ? in the URL), then you can try this:
RewriteEngine On
RewriteCond %{QUERY_STRING} x=(.*)
RewriteRule ^ http://www.somesite.com/? [R=301,L]
You've got most of it right, it seems, but your rule needs to have a match, and your target (the http://www.somesite.com/) needs a ? at the end so that any query string before the rewrite won't get appended.
In Apache 2.4 or newer you can use the QSD query string discard flag:
RewriteEngine On
RewriteCond %{QUERY_STRING} x=(.*)
RewriteRule .* http://www.somesite.com/ [R=301,L,QSD]
I have a simple htaccess redirect to send visitors from website.com/promotions to website.com/go/promotions. If I use the code below I get a redirect loop error:
RewriteEngine on
RewriteCond %{REQUEST_URL} !^go$
RewriteRule promotion/index.html go/promotion/index.html [R,L,NC]
The RewriteCond is supposed to prevent the loop by not redirecting if the request url contains "go" but it doesn't appear to be working.
In addition I'm trying to set up a regex so that promotion/anypage.html will be redirected to go/promotion/anypage.html. I tried the following code but it wouldn't match anything:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^go$
RewriteRule ^promotion/(.*)$ go/promotion/$1 [R,L,NC]
Does anybody have an clues as to why either of these blocks isn't working properly ?
Cheers
%{REQUEST_URL} isn't a var you can match against, you're probably thinking of %{REQUEST_URI}, but it starts with a leading slash so ^go will never match anything.
You just need a single rule:
RewriteEngine On
RewriteRule ^/?promotion/(.*)$ /go/promotion/$1 [R,L]
Or you can use mod_alias:
Redirect /promotion/ /go/promotion/
You're checking if the entire URL is just "go" on it's own, which it's not:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/?go/
RewriteRule promotion/index.html go/promotion/index.html [R,L,NC]
I need to make some 301 redirects, like this:
/!go?ln=vector.dpsp&refs_=&m$id=27007&m$mid=27013 to http://domain.com/catalog/paz-320412-vektor.htm
/!go?ln=1223-15-57-1223.html&m$id=27148&m$mid=27940 to http://domain.com/catalog/gruzoviki/sedelnie-tyagachi-man
I tryed this code in .htaccess:
RewriteCond %{QUERY_STRING} ln=vector.dpsp&refs_=&m$id=27007&m$mid=27013
RedirectPermanent /!go http://domain.com/catalog/paz-320412-vektor.htm?
RewriteCond %{QUERY_STRING} ln=1223-15-57-1223.html&m$id=27148&m$mid=27940
RedirectPermanent /!go http://domain.com/catalog/gruzoviki/sedelnie-tyagachi-man?
But all this two urls are catched with first block and redirect goes always into http://domain.com/catalog/paz-320412-vektor.htm
What am I doing wrong?
There's a couple of things wrong here. First, you need to escape the $ symbols in your expression matching the %{QUERY_STRING}, it's a reserved symbol (for stuff like backreferences). The second thing is a RewriteCond doesn't affect a RedirectPermanent. Rewrite directives are part of mod_rewrite and Redirect directives are part of mod_alias, you can't tie a rewrite condition to a redirect, you need to use RewriteRule:
RewriteCond %{QUERY_STRING} ln=vector.dpsp&refs_=&m\$id=27007&m\$mid=27013
RewriteRule ^\!go$ http://domain.com/catalog/paz-320412-vektor.htm? [R=301,L]
RewriteCond %{QUERY_STRING} ln=1223-15-57-1223.html&m\$id=27148&m\$mid=27940
RewriteRule ^\!go$ http://domain.com/catalog/gruzoviki/sedelnie-tyagachi-man? [R=301,L]