Using htaccess how can I 301 redirect the following?
domain.com/index.php?r=apiv2/* to app.domain.com/index.php?r=apiv2/*
Where * is a wildcard for anything
This is my attempt so far:
RewriteCond %{QUERY_STRING} r=apiv2(.*)
RewriteRule ^index\.php$ https://app.domain.com/index.php?r=apiv2/$1 [L,R=301]
Thanks in advance!
You can use:
RewriteCond %{QUERY_STRING} r=apiv2(.*)
RewriteRule ^index\.php$ https://app.domain.com/index.php?r=apiv2%1 [L,R=301]
With %1 back-reference to the last matched RewriteCond pattern
Related
i would like redirect permanent 301 :
https://www.toto.com/index.php?id=4
to
https://www.toto.com/?id=4
this could be fine ? =>
RewriteRule index.php?id=([0-9]+)$ /?id=$1 [L,NC,R=301]
Thanks !
You cannot match Query String i.e. ? and part after that in RewriteRule.
You can use following rule to remove index.php from all paths but keep query string:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ %1 [L,R=301,NE]
Need help ;)
How to redirect this link?
mydomain.com/selbständige?catid=141&id=141:kredit-für-selbstständige-ohne-schufa
Tested with:
RewriteCond %{QUERY_STRING} ^(.+&)?selbständige?catid=141(&.+)?$
RewriteRule ^/$ http://test.com? [R=301,L]
RewriteCond %{QUERY_STRING} ^(.+&)selbst%E4ndige?catid=141(&.+)?$
RewriteRule ^/$ http://test.com? [R=301,L]
redirect 301 "/selbständige?catid=141&id=141:kredit-für-selbstständige-ohne-schufa" http://test.com
...and so on.
No normal workflow works.
Try :
RewriteEngine on
RewriteCond %{THE_REQUEST} /selbst.+ndige\?catid=141&id=141:kredit-f.+r-selbstst.+ndige-ohne-schufa [NC]
RewriteRule ^ http://test.com? [L,R]
I used .+ to match against special chars in the uri.
I neee to redirect
http://www.example.com.au/recipes/recipe.aspx?name=91-Sunflower%20Crackers
to https://www.example.com.au/recipes/
I followed so many posts but this is not redirecting at all.
This is my code
RewriteCond %{QUERY_STRING} ^name=91-Sunflower%20Crackers$
RewriteRule ^/recipes/recipe\.aspx?$ /recipes/? [NE,L,R]
What is the error here ?
This rule should work:
RewriteCond %{QUERY_STRING} "^name=91-Sunflower(\s|%20)Crackers$" [NC]
RewriteRule ^recipes/recipe\.aspx?$ /recipes/? [NC,L,R]
No leading slash in RewriteRule and use (\s|%20) in RewriteCond to match a whitespace.
I need to redirect this page:
http://orbit-cs.com/Orbit/SendFile.asp?DBID=1&LNGID=1&GID=882
To this:
http://orbit-cs.com/news/
.htaccess:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^DBID=1&LNGID=1&GID=882$
RewriteRule ^orbit-cs.com/Orbit/SendFile.asp?$ orbit-cs.com/news [L,R=301]
Any idea why it's not working?
You don't match domain name in RewriteRule. That is used for matching REQUEST_URI only. Use this rule:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^DBID=1&LNGID=1&GID=882$ [NC]
RewriteRule ^/?Orbit/SendFile\.asp$ orbit-cs.com/news? [NC,L,R=301]
I put in a 301 redirect for my /index.php as recommended for SEO purposes. Unfortunately this prevents any params being accepted.
example.com/index.php should redirect to example.com
example.com/index.php?anything should stay at example.com/index.php?anything
example.com/index.php?f=bar&b=foo should stay at example.com/index.php?f=bar&b=foo
My attempted fix is below:
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s\/index\.php\s
RewriteCond %{QUERY_STRING} =""
RewriteRule . http://${HTTP_HOST}/ [R=301,L]
Turns out the answer for the scenario is a combination of Deadooshka's answer and a POST fix.
RewriteCond %{THE_REQUEST} \s\/index\.php\s
RewriteCond %{QUERY_STRING} =""
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*)index.php$ /$1 [R=301,L]