Redirect Folder and Contents to New Site - .htaccess

A WordPress site with a shopping cart plugin is being deactivated and the products are moving to a new site. I'm trying to redirect (301) all references to products at the WP site to the new site. I've tried a variety of things including examples I found here with no success.
I started with this in the .htaccess file at the WP site before the WP rules:
RedirectMatch 301 ^product/(.*)$ http://www.newsite.com/products/
I also tried it as a rewrite:
RewriteRule ^product/(.*) http://www.newsite.com/products/$1 [R=301,L]
I don't care which product is being referenced. I just want to send all such references to the main products page at the new site.
I'm pretty lightweight regarding htaccess, having mostly used it for very simple things. And my regular expressions might be off as well. I'm out of my depth for this one. Can anyone point me in the right direction?

Ignoring my stupidity for not getting the .htaccess file uploaded to the right place, eventually this rule worked:
RedirectMatch 301 product/.* http://www.newsite.com/products/

Related

TYPO3 10 .htaccess redirect old links to new links not working

While updating a website (completely new page tree, IDs have changed), the old links need to redirect to the new links. Domain stays the same.
This is the first thing I write in my .htaccess
RewriteEngine on
Redirect 301 /index.php?id=5 /contact
Redirect 301 /test.html /xy.html
Redirect 301 /index.php?id=6 /imprint
# and many more
test.html successfully links to xy.html (just a test, they don't even exist and correctly show the 404 page)
the index.php?id=x redirects however do not work. They actually still open whatever new page has this ID.
I don't understand why it's not working. Is TYPO3 interfering? I though I would be safe if I write it as the first thing in my .htaccess.
TYPO3 does not interfere as the rules in the .htaccess file are evaluated before.
Another option could be to use the redirect module of TYPO3 for creating the redirects. Those can then be created in the backend and maintained by editors. A small drawback is that performance is not that perfect as in .htaccess but it is much more convenient.

How to redirect entire domain to new domain except homepage via htaccess

So I have found some questions that are close to what I need, but I haven't found exactly what I'm looking for.
While I've worked with htaccess files in the past, it's pretty much been just copying and pasting code that is proven to work, or just doing simple 301 redirects. To be honest, I get pretty confused when looking at htaccess rewrite rules, so unfortunately are not going to be able to do from scratch. So I'm really hoping there is someone kind enough to provide a code example just using placeholder domain names.
Here is my situation. I'm doing work for a company who has split up into different divisions (4). So they want to take the site on their current domain, move it to a different domain. Then put up a simple html splash page on the old domain that provides links to the 4 different sites they will have (one of those being what was the old site on a new domain).
So I need to redirect everything from olddomain.com to newdomain.com with the exception of the homepage. Not sure if this matters, but site that was on the old domain was a WordPress site so technically is index.php. But the new site/splash page is named index.html.
Thanks in advance!
So I need to redirect everything from olddomain.com to newdomain.com with the exception of the homepage.
You can use this rule in the site root .htaccess of olddomain.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !/(css|js|images)/ [NC]
RewriteRule . http://newdomain.com%{REQUEST_URI} [L,NE,R=301]
RewriteRule . will match everything except the home page just make sure this rule is the first rule in your .htaccess.

Moving VERY old website to New Domain

I have been creating a new website for a company and would like some advice on writing a rewrite file.
I obviously would like to keep our current rankings and transfer them to the new site and i am just wanting to make sure I am doing it correctly.
Would a standard 301 redirect with old links to new links work if I also write a rewrite to the home page?
This isn't my area and any help would be great.
Justine
This Redirect htaccess code below in an htaccess file in the old site's folder would redirect all old site pages and posts to identical matching pages and posts with the same identical structure on the new site/domain.
RedirectMatch 301 ^/$ http://www.newdomain.com/$1
For some web hosts you need to include the folder name where the website is physically installed. olddomain.com would be the name of the folder and not the URL|URI name.
RedirectMatch 301 ^/olddomain.com$ http://www.newdomain.com/$1

Redirect in htaccess from one path to another

I would like to change our site structure a little bit and decided to have the product overview not in http://www.example.com/en/ but in http://www.example.com/en/products/
I did not manage it to redirect it from /en/ to /en/products/ (or /en to /en/products/).
The page is not online so far (Testmode) and I don't have to care about 301 Pages for Google at the Moment.
Can anybody help?

Old pages PR to

I have site that has many links to its pages. And I will completely renew site, update CMS, content and page structure. Domain remains the same.
What will get users in browser if they find somewhere on the Internet old link
to old sites page and follow by that link while it's already a new site and
old page where link leads to doesn't exist?
How to make a redirect or something from these old links if old
pages not open to root of domain?
What's about Google in that case how do not lost PR and
redirect that PR weight of old pages to main domain?
I am kindly appreciate any relative discussion on this topic because it's really interesting from all sides.
What will get users in browser if they find somewhere on the Internet old link to old sites page and follow by that link while it's already a new site and old page where link leads to doesn't exist?
They will get a 404 Not Found.
How to make a redirect or something from these old links if old pages not open to root of domain?
You'll need to create a 301 redirect from every old page to the equivalent new page. You can do it using mod_alias:
RedirectMatch 301 ^/old_page/(.*)$ /new_page/$1
or mod_rewrite:
RewriteRule ^old_page/(.*)$ /new_page/$1 [L,R=301]
You'll obviously need to tailor the matching expressions and targets to your specific needs. If you have a lot of individual URL's that need redirecting, you may want to look into creating a RewriteMap.
What's about Google in that case how do not lost PR and redirect that PR weight of old pages to main domain?
As long as you use 301 redirects (a permanent redirect, as opposed to 302, a temporary redirect) Google's page ranking will transfer to the new URL.
What's better to use mod_alias or mod_rewrite in this situation and why?
Either is fine, but mod_rewrite gives you a lot more options and allows for rewrite maps. But if you are doing something simple, mod_alias is fine.
Again the same with 301 and 302 what's better to use here?
You want 301 here. It means "the resource that you requested has permanently moved to HERE" as opposed to a 302 which means "the resource that you requested isn't here right now, but in the mean time, you can find it HERE". Also, Google won't transfer any page ranking to the new page if you only do a 302 redirect, since it's meant only for temporary redirects. Not when a page has permanently moved to a new URL.
And the last I just looked on the old pages they all like domain.tld/index.php?id=77 does this rule correct RewriteRule ^index.php?id=(*)$ / [L,R=301] in that case for any id number to root?
This rule will not work. You cannot match against the query string (the ?id= part) in a RewriteRule, only against the %{QUERY_STRING} var in aRewriteCond. Also(*)` is probably not what you want.
This will 301 redirect any request for /index.php?id=N where N is any number, to the document root.
RewriteCond %{QUERY_STRING} ^id=([0-9]+)
RewriteRule ^index.php$ / [L,R=301]

Resources