I have a little problem with my 301 redirects.
I have this URL,
https://www.example.com/directory/?rapidoysencillo
and I need to redirect to,
https://www.example.com/directory?provenanceCode=myprovenance
I tried to use
RewriteCond `%{QUERY_STRING} ^rapidoysencillo=([^&]+)
but didn’t work.
You can use this rule:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^rapidoysencillo$ [NC]
RewriteRule ^directory/?$ %{REQUEST_URI}?provenanceCode=myprovenance [L,NC,R=302]
Related
I'm trying to do a 301 with a query string.
I want to redirect
www.mydomain.com/page1.php?id=12
To
www.mydomain.com/page2.php?id=12
I've already tried this in .htaccess:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page_id=([0-9]+)$
RewriteRule ^page2.php?page_id=%1 [R=301,L]
You may use this redirect rule:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=\d+$
RewriteRule ^page1\.php$ /page2.php [R=301,L,NC]
Query string will be automatically copied over to new URL.
I have multiple pages that I need to 301 redirect, but only if it DOES NOT have the parameters ?embed=true in its url.
for example:
www.example.com/old-page.php should redirect to www.example.com/new-page.php
but
www.example.com/old-page.php?embed=true should not redirect at all
Can anyone please help? So far I have the following, but it doesn't work.
RewriteCond %{QUERY_STRING} !^embed=true [NC]
RewriteRule ^/old-page.php$ /new-page.php [L,R=301]
RewriteRule ^/old-page2.php$ /new-page2.php [L,R=301]
You can try below code :
RewriteCond %{QUERY_STRING} !embed=true [NC]
RewriteRule ^/?old-page.php$ /new-page.php [L,R=301]
Try in Guest or Incognito mode after applying above rules.
I need to 301 redirect an old url that contained a get parameter in the url.
I need to 301 the URL:
http://www.website.com/choose?cat=womens
to this URL:
http://www.website.com/womens
I have searched and tried without it working:
RewriteCond %{QUERY_STRING} cat=womens
RewriteRule ^choose\.php$ /womens [L,R=301]
Where am I going wrong?
You're almost correct, just 2 issues:
.php wasn't there in your original URI after choose as per the question
You need to add ? in target to strip original query string
You can use:
RewriteCond %{QUERY_STRING} (?:^|&)cat=([^&]+) [NC]
RewriteRule ^choose(?:\.php)?$ /%1? [L,R=301,NC]
Try these:
RewriteCond %{QUERY_STRING} ^cat=womens$
RewriteRule ^choose$ http://www.website.com/womens? [R=301,L]
I want to create a condition that if page has parameter in URL like ?print=1 - redirect this page to itself without any querystring.
Example:
I want this page:
http://sos-med.com/en/specific_page.html?print=1&ok=1
tp redirect (301) to the same URL with no Query string:
http://sos-med.com/en/specific_page.html
My code is:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^*print=*$ [NC]
RewriteRule ^(.*)$ %{REQUEST_URI}?
I have no test server, so can you tell me if my code is ok?
The code above is for every page on website. And before implementing that rule I would like to try the redirect for one specific page (see my example).
How to modify the code to work with "specific_page.html" only?
I want only .htaccess solution, not PHP code.
You're close, your %{QUERY_STRING} regex isn't right, and you're missing the 301 redirect flag:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^print=.*$ [NC]
RewriteRule ^(.*)$ %{REQUEST_URI}? [L,R=301]
Try that.
Thanks, and If I want to redirect single specific page: sos-med.com/en/aaa.html?print=1&ok=1 to sos-med.com/en/aaa.html ? –
Then you'd change what the rule matches against:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^print=.*$ [NC]
RewriteRule ^en/aaa.html$ %{REQUEST_URI}? [L,R=301]
Try this one instead :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*&)?print= [NC]
RewriteRule ^(.*)$ /$1? [L,R=301]
I am moving my site to new domain. Need to redirect pages
from
old-site.com/oldpage.php?id=X
to
new-site.com/newpage-X
(X is number)
Why this rule does not work?
RewriteEngine on
RewriteRule ^oldpage.php?id=(.*)$ http://new-site.com/newpage-$1 [R=301,L]
The RewriteRule does only operate on the URL path and not the URL query. You need to use the RewriteCond directive to test the URL query (%{QUERY_STRING}). So try this rule:
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)id=([^&]+)&?(.*)?$
RewriteRule ^oldpage\.php$ http://new.example.com/newpage-%3?%1%4 [L,R=301]
This rule will also preserve other parameters in the query.
I suspect that you will need to use QUERY_STRING
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^oldpage\.php$ http://new-site.com/newpage-%1 [R=301,L]
Hope this helps