htaccess: Redirect vs. Redirect 301 - .htaccess

I was just looking in one of my .htaccess files and noticed the following:
Redirect /old-page /new-page
I was expecting to see Redirect 301 or Redirect 302, but it only said Redirect and works just fine.
I'm curios if 301 or 302 isn't indicated what does the redirect default to? 301? 302? Something else?

This line:
Redirect /old-page /new-page
Means use 302 since 302 is default value here.
To use 301:
Redirect 301 /old-page /new-page
See 301 directive documentation

Related

Problem with path 301 redirects in htaccess

We're trying to redirect a bunch of category URLs like this:
Redirect 301 /table/ https://www.example.com/abc/
Redirect 301 /table/accessoires/ https://www.example.com/def/
Redirect 301 /table/accessoires/tablecloth/ https://www.example.com/ghj/
The first redirect works correctly. But why do the other 2 don't work?
Order matters. The more specific rules should be first.
Redirect 301 /table/accessoires/tablecloth/ https://www.example.com/ghj/
Redirect 301 /table/accessoires/ https://www.example.com/def
Redirect 301 /table/ https://www.example.com/abc/

301 Redirect in .htaccess is appending old file path/name to new url

I have two URLs: old-site.com and new-site.com.
My root folder on the old-site.com has NO FILES in it but only the .htaccess file. I don’t want to use the old domain anymore. However, I do want to pass the link juice to the new domain. Therefore, I created 301 Redirects in the .htaccess file and put it in the root folder on the old-site.com.
Why would the Redirect 301 append the “old-site.com/…” to the new-site.com?
My entire .htaccess looks like this (I skipped a few links to shorten it):
#Begin 301 Redirects
Redirect 301 / https://www.new-site.com/
Redirect 301 /contactus https://www.new-site/contact-us/
Redirect 301 /rentals https://www.new-site/lodging/
Redirect 301 /lift.html https://www.new-site/our-rentals/boat/
Redirect 301 /rentals.html https://www.new-site/our-rentals/
Redirect 301 /map.html https://www.new-site/contact-us/
Redirect 301 /giftshop https://www.new-site/store/gift-shop/
#End 301 Redirects
I don’t have any Rewrites. The above is my entire code.
The following redirect works fine:
Redirect 301 / https://www.new-site.com/
However, any other redirect creates the following absolute path on the new-site.com with a 404 error:
If I redirect:
Redirect 301 /contactus https://www.new-site/contact-us/
It goes to:
https://www.new-site.com/old-site.com/contactus
or
If I redirect:
Redirect 301 /lift.html https://www.new-site/lift/
It goes to:
https://www.new-site.com/old-site.com/lift.html
Why would the Redirect 301 append the “old-site.com/…” to the new-site.com?
Thank you,
Derek
Your rules will not do what you need correct because of this line Redirect 301 / https://www.new-site.com/ which will match any request first and if you put it in the last it will also match any request so , if you want it to match only root use RedirectMatch to be able to use regex like this :
RedirectMatch 301 /?$ https://www.new-site.com/
By this the rest of rules will work as expected .
Note: clear browser cache the test

htaccess Redirect 301 redirects to wrong url

I've created a bunch of 301 redirects in my .htaccess, for example
Redirect 301 / /de/
Redirect 301 /site_1/ https://www.new.com/de/company/site_1/
Redirect 301 /services/site_2/ https://www.new.com/de/services/site_1/
and so on.
When I enter
www.old.com/site_1/ (wrong)
I get directed to
https://www.new.com/de/site_1/ (services folder missing)
It seems that the parent folder is missing in the redirected URL. Same for all other sites that reside in folders.
Redirect 301 / /de/
Redirect 301 /site_1/ https://www.new.com/de/company/site_1/
Redirect 301 /services/site_2/ https://www.new.com/de/services/site_1/
Since the mod_alias Redirect directive is prefix-matching, a request for www.old.com/site_1/ would actually get caught by your first (most general) rule. And everything after the match (ie. site_1/) gets appended onto the end of the target URL (ie. /de/), so the resulting redirect becomes /de/site_1/ (but not to new.com as you've stated?).
You could resolve this by reversing the directives, to have the most specific matches first. For example:
Redirect 301 /services/site_2/ https://www.new.com/de/services/site_1/
Redirect 301 /site_1/ https://www.new.com/de/company/site_1/
Redirect 301 / /de/
Or, as you mentioned in comments, use RedirectMatch instead - which is not prefix-matching and matches against a specific regex instead. Although you will still need to modify the pattern. Something like:
RedirectMatch 301 ^/$ /de/
RedirectMatch 301 ^/site_1/$ https://www.new.com/de/company/site_1/
RedirectMatch 301 ^/services/site_2/$ https://www.new.com/de/services/site_1/
Although this now matches the exact URL, which may or may not be what you require.

301 Redirect just first Subfolder

I have a 301 Redirect from one page to another
REDIRECT 301 /cloud-computing /it-infrastructure/cloud-computing
Now when i use this redirect also the subpages of cloud-computing are affected by this 301 redirect, but they have to be redirected somewhere else. How can i just redirect the folder and not the subpages?
You should be using RedirectMatch for precise matching using regex:
RedirectMatch 301 ^/cloud-computing/?$ /it-infrastructure/cloud-computing
Clear your browser cache before testing the change.

Magento 301 htacess redirect not working at all

i am writing a 301 redirects via htaccess redirect old traffic to new urls
ex
i have old url
http://www.thebedroom.com.au/catalogue/accessories/product134
i need to redirect this request to
http://www.thebedroom.com.au/melbourne-demons-bean-bag-cover.html
so i wrote a code on magento httpacess like below
Redirect 301 http://www.thebedroom.com.au/catalogue/accessories/product134 http://www.thebedroom.com.au/melbourne-demons-bean-bag-cover.html
no luck
and also tried
Redirect 301 ^accessories/product134 http://www.thebedroom.com.au/melbourne-demons-bean-bag-cover.html
but this not redirectoring and show the same url on browser window.
anyone know what is the issue here
thank you
Try:
Redirect 301 /catalogue/accessories/product134 http://www.thebedroom.com.au/melbourne-demons-bean-bag-cover.html
or
RedirectMatch 301 product134 http://www.thebedroom.com.au/melbourne-demons-bean-bag-cover.html
which will redirect if there's any instance of product134 in the URI.

Resources