htaccess redirect 301 does not work - .htaccess

There was an old site, and all your URLs have changed.
One URL that was well found on Google was:
mydomain.com/datacenters
Now I want to redirect this URL to:
mydomain.com/data-centers
In htaccess I did:
redirect 301 /datacenters /data-centers
But it does not work, what am I doing wrong?

Only work with:
RewriteRule ^datacenters http://mydomain.bla/data-centers [L,R=301,NC]

Related

How to 301 redirect old website to a new one

I would like to 301 redirect my old domain say m.oldwebsite.com to m.newwebsite.com.
I believe the line below will redirect and keep the url path.
RewriteRule ^(.*)$ https://m.newwebsite.com/$1 [L,R=301]
What I need is for all links on m.oldwebsite.com to redirect to the home page of m.newwebsite.com.
Forexample:
m.oldwebsite.com/path/to
to redirect to
m.oldwebsite.com
I couldn't find a clear solution for this.
Thanks!
Remove $1 parameter from rewrite and it's done, all redirect to homepage.

htaccess 301 redirect not working for new subdomain site

I'm moving my site so wanted to test a page and redirect in the htaccess file:
I wanted to redirect
http://www.martinspencephotography.co.uk/blog/yes/mini-photo-series-minimalism-gallows-hill-outside-cloughmills
to
http://landscape.martinspencephotography.co.uk/minimalism-at-gallows-hill/
using the following in the .htaccess file:
Redirect 301 /blog/yes/mini-photo-series-minimalism-gallows-hill-outside-cloughmill http://landscape.martinspencephotography.co.uk/minimalism-at-gallows-hill
It didn't works there any reason why this might not work?
Try
RewriteRule your_page.html
http://your.url.fr/yournewpage.html [R=301]
And what about
http://www.martinspencephotography.co.uk/blog/yes/mini-photo-series-minimalism-gallows-hill-outside-cloughmills http://landscape.martinspencephotography.co.uk/minimalism-at-gallows-hill/ [R=301]
So the answer was to use DRUPAL NODE...

How to do 301 redirects with folders & subfolders?

I need to redirect all the old URLs on my site to new URLs, but am having issues. A given URL and its subfolders need redirecting to the same page.
For example, this is the first one:
redirect 301 /panache/sports-bra/ http://www.newdomain.co.uk/sports-bra.html
This works ok. However there are these size sub-pages which need to redirect to the same location:
redirect 301 /panache/sports-bra/30DD http://www.newdomain.co.uk/sports-bra.html
redirect 301 /panache/sports-bra/30E http://www.newdomain.co.uk/sports-bra.html
redirect 301 /panache/sports-bra/30F http://www.newdomain.co.uk/sports-bra.html
And these don't work, I end up at a location like the following:
http://www.newdomain.co.uk/sports-bra.html30DD
See the way the last part of the path is appended to the url? I'm guessing it's because the second redirect is conflicting with the initial 301 redirect?
I have also tried using this rewrite rule but have had no luck. The site is Magento so I don't know if this has some effect? mod_rewrite is enabled on the server.
RewriteRule ^panache/sports-bra/ http://www.newdomain.co.uk/sports-bra.html [R=301]
Any help mucha ppreciated.
Try this.
RewriteEngine on
RewriteRule ^(panache/sports-bra/.*)$ /sports-bra.html [L,R=301,NC]

301 redirect from htaccess

I'm trying to create permanent redirects for outdated URL's on my site.
For example I have: www.mydomain.com/?v=tv and want it have a permanent 301 redirect to www.mydomain.com/tv.php
I tried this code in my htaccess file but it did not work:
Redirect /?v=tv http://mydomain.com/tv.php
Any Help?
RewriteRule ^tv.php$ http://guessthelogo.com/?v=tv [R=301,L]
I think your missing "301" after "Redirect":
Redirect 301 /?v=tv http://guessthelogo.com/tv.php

301 redirect after url rewrite

I did some htaccess URL rewrite. To keep my google ranking I must redirect the old URL to the new one; the problem is the old URL still 'exist' and I'm not sure how to do the redirect. This is an example:
old url: mypage.php?id=myId
which now is rewritten as: mypage-myId.html
this is the htaccess directive
RewriteRule ^mypage-([A-Za-z0-9_-]+).html$ mypage.php?id=$1 [L]
now I want to 301 redirect all the old url (mypage.php?id=myIds) to the new url (mypage-myIds.html).
I tried this at the top of my htaccess file:
redirect 301 mypage.php?id=1 to mypage-1.html
but nothing happens, the page stays on mypage.php?id=1.
What's wrong with this? I found another post about this problem
url rewrite & redirect question
but the solution wasn't that clear to me.
Thanks in advance
Vittorio
You could try this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([A-Za-z0-9_-]+)$ # fetch ID
RewriteRule ^mypage\.php$ http://domain.com/mypage-%1.html [R=301,L] # redirect old URL to new
RewriteRule ^mypage-([A-Za-z0-9_-]+)\.html$ mypage.php?id=$1 [L] # rewrite

Resources