I'm using something similar to the following:
RewriteEngine on
Redirect 301 / http://newdomain.co.uk/link/
Redirect 301 /showcase.asp?showcaseid=1 http://newdomain.co.uk/track1
Redirect 301 /showcase.asp?showcaseid=2 http://newdomain.co.uk/track2
Redirect 301 /showcase.asp?showcaseid=3 http://newdomain.co.uk/track3
Redirect 301 /showcase http://newdomain.co.uk/link/tracks
With that in mind any URL other than the mentione would go to http://newdomain.co.uk/link
Which is fine however any of the other URL's that use a "?" go to say http://newdomain.co.uk/link/showcaseid=1 for /showcase.asp?showcaseid=1
Also with the
Redirect 301 /showcase http://newdomain.co.uk/link/tracks
can I just write as follows:
Redirect 301 /showcase tracks
You can't match against the query string (everything after the ?) in a Redirect directive. You have to use mod_rewrite's %{QUERY_STRING} variable:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^showcaseid=([0-9])
RewriteRule ^showcase\.asp$ http://newdomain.co.uk/track%1 [L,R=301]
RewriteRule ^showcase$ http://newdomain.co.uk/link/tracks [L,R=301]
RewriteRUle ^$ http://newdomain.co.uk/link/ [L,R=301]
Note that the order is important. You generally want the more general matching rules to be at the end.
Related
I would like to make some massive redirects in .htaccess because of a migration. I'm using both RewriteRule and Redirect 301. But the RewriteRule keeps overwriting the Redirect 301 rules, despite of the order.
For example:
I would like to redirect /retraites-nl-cat-595.html to https://www.vihara.nl/meditatieretraites/
But all the other url's that contains 595 to https://www.vihara.nl/tag/vipassana/
I have this in .htaccess:
RewriteEngine on
RewriteRule ^$ https://www.vihara.nl [R=301]
Redirect 301 /retraites-nl-cat-595.html https://www.vihara.nl/meditatieretraites/
RewriteRule ^(.*)595(.*)$ https://www.vihara.nl/tag/vipassana/ [L,R=301]
But this is not working because the RewriteRule is overruling the Redirect 301 rule. The same happens when I switch the order of the last 2 lines.
Is there a way to change this? So the Redirect 301 will be overruling the Rewrite rule, instead of the other way around?
First I need to redirect these pages to another page in a different domain
Redirect 301 /example1 http://newdomain.com/test1
Redirect 301 /example2 http://newdomain.com/random1
Note the pages are not the same in the new domain (e.g., /example1 to /test1)
After that, I need redirect the rest of the pages to newdomain.com
E.g., Redirect 301 (everything else) to http://newdomain.com
Try below rule, using mod rewrite I am assuming you have mod rewrite enabled.
RewriteEngine On
RewriteRule ^example1$ http://newdomain.com/test1 [R=301,L]
RewriteRule ^example2$ http://newdomain.com/random1 [R=301,L]
RewriteCond %{REQUEST_URI} !^(example1|example2)
RewriteRule ^ http://newdomain.com [R=301,L]
If you want to use mod-alias , you can use these redirects :
RedirectMatch 301 ^/example1/?$ http://example.com/test1
RedirectMatch 301 ^/example2/?$ http://example.com/random1
#redirect everything else to the homepage of example.com
RedirectMatch ^.+$ http://example.com/
Clear your browser cache before testing these redirects.
Try this in your .htaccess
RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/ [R=301]
I tried the following code in .htaccess to 301 redirect www.example.com/?content=file.php&id=16 www.example.com/file/This-is-the-title/16
RewriteEngine on
Redirect 301 /?content=file.php&id=16 /file/This-is-the-title/16
But it's not redirecting. The URL remains as it is.
What am I doing wrong?
P.S. I'm not asking for rewrite or so. I need a 301 redirect.
The Redirect directive doesn't match query strings. Use this instead:
RewriteEngine on
RewriteCond %{QUERY_STRING} =content=file.php&id=16
RewriteRule ^$ /file/This-is-the-title/16? [R=301,L]
A new website has just gone live and there is a htaccess file which has 301 redirects in order to direct people from the old pages on the old domain to the new pages on the new domain.
However, because there is a ? and = symbol in the links it's not working.
I understand I'll need to take advantage of the query string, but I can't work out how to get these three examples working.
Redirect 301 /index.cfm?task=what_we_do http://domain.com/services/
Redirect 301 /pagecontent/_newsitem.cfm?newsid=63 http://domain.com/name-of-article/
Redirect 301 /pagecontent/_people.cfm?peopleid=3 http://domain.com/about-us/meet-the-team/john-smith/
Can anyone help?
You can't use a query string in the redirect. you have to use mod_rewrite.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^task=what_we_do$
RewriteRule ^index.cfm http://domain.com/services/? [R=301,L]
RewriteCond %{QUERY_STRING} ^_newsid=63$
RewriteRule ^pagecontent/_newsitem.cfm http://domain.com/name-of-article/? [R=301,L]
RewriteCond %{QUERY_STRING} ^_peopleid=3$
RewriteRule ^pagecontent/_people.cfm http://domain.com/about-us/meet-the-team/john-smith/? [R=301,L]
I want to 301 redirect from
domain.com/?test-article.php
to
domain.com/full-article/test-article.php
Here is my code what i am trying to use and its not working.
redirect 301 /?test-article.php http://domain.com/full-article/test-article.php
or
rewriteRule /?test-article.php http://domain.com/full-article/test-article.php [R=301,L]
if i use without '?' then it re-directs from
/test-article.php
to
http://domain.com/full-article/test-article.php
So something has to do with '?'
You can't match against the query string using a pattern of a Redirect or RewriteRule. You need to use the %{QUERY_STRING} variable and mod_rewrite:
RewriteCond %{QUERY_STRING} ^test-article$
RewriteRule ^/?$ http://domain.com/full-article/test-article.php [R=301,L]