Moving VERY old website to New Domain - .htaccess

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

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.

.httaccess 301 redirect subdomain with path wildcards

I need to 301 redirect URL's I was using on my old website/platform to my new website on Shopify.
Old url structure:
https://shop.olddomain.com/path/name-of-page
What I would like to have is a wildcard for http/https, because the platform changed my website from insecure to secure back when Google started ranking based on that.
I would also need a wildcard for /path/name-of-page, because I have hundreds of URL's with that structure and I'm not trying to map each of those URL's to the new URL's. Basically, my goal is to make sure those old URL's don't go to a dead end 404, and are redirected to the new website homepage.
So http/https://shop.olddomain.com/* should redirect to https://newdomain.com
In your .htaccess for shop.olddomain.com place
Redirect 301 /shopoldpath https://newdomain.com

Redirect domain to subfolder with some specific pages fallback

I need to change website domain from www.domain.com to www.newdomain.com/en but I also need to specify some pages from old website to new website like www.domain.com/page to www.newdomain.com/en/subfolder/subfolder/page.
Last thing should be great keeping one subfolder path of old website free of redirect like www.domain.com/admin in order to keep backend access to old website.
What would you suggest me to add to old site htaccess file in order to achieve that with a sort of fallback mechanism for specifc pages and whole domain to subdirectory?
Thank you
You can add the following 301 redirect to your oldsite/htaccess :
Redirect 301 / http://newdomain.com/en/subfolder/subfolder/
This will redirect all requests from your old site to the subfolder in your new site
Edit : as per your comment,
to exclude a specific path from the redirection, you may use RedirectMatch
RedirectMatch 301 ^/((?!page1|page2).*) http://newdomain.com/en/subfolder/subfolder/$1
This will not redirect /page1 or /page2 .

Redirect Folder and Contents to New Site

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/

Trouble redirecting all pages in a folder to a page at root level

I've searched, tried various examples, and none, other than creating an explicit list of redirect statements seems to work.
The biggest issue I have is that, although I have access to deploy web pages to the site, I do not have access to any web hosting control panel - site access was inherited, and until now it's been fine, but I think that it is either running an old version of apache, or rewrite rules are not allowed.
Anywa, over the years, the site has changed several times, and after registering the site with Google Webtools, I found the list of pages that gave crawl errors, so created an HTACCESS file to deal with these.
Over the years, there have been folders deployed and named in camel case and all lower case, and so all I wanted to do was to redirect all files in a folder to the new folder in the .htaccess file level, i.e.
My .HTACCESS currently has 120 lines, and an example batch are as follows:
redirect 301 /challenge/stanley_steamer.htm /lsr_history.html
redirect 301 /challenge/stanley_steamer.html /lsr_history.html
redirect 301 /Challenge/index.htm /lsr_history.html
redirect 301 /Challenge/Record.htm /lsr_history.html
redirect 301 /Challenge/Stanley_Steamer.htm /lsr_history.html
redirect 301 /Challenge/Sponsors/Avery_Weigh-Tronix.htm /sponsors.html
redirect 301 /contact/index.html /contact.html
redirect 301 /design/details.html /design.html
redirect 301 /design/index.html /design.html
redirect 301 /Design/Engine-drive_train.htm /design.html
redirect 301 /Design/Rear.htm /design.html
redirect 301 /Design/Home_Page.htm /design.html
redirect 301 /Design/index.htm /design.html
As you can see, I have some cases where the folder name is camel, others lower, and other cases where there is a htm and an html file of the same name that is listed in the crawl error log.
All I want to do is, in the example above, redirect all pages from /Challenge/ and /challenge/ to lsr_history.html, but all files in /Challenge/Sponsors/ to sponsors.html.
I also have a huge list of individual team pages that I list one by one and each one redirects to the new team page.
I've tried examples like:
RedirectMatch 301 ^/[Cc]hallenge/ /challenge.html, but this returns a 'Error 404 Not found'.
Any ideas or examples of how I can cut down my htaccess file to simplify this will be gratefully received.
Regards
Martin
I wouldn't bother searching for cases inside the match string for this kind of thing if I could avoid it - have you tried just specifying the RedirectMatch in lowercase, and appending [NC] to the end of every line? (that will tell mod_rewrite to ignore case and match regardless, which may save you some time)
if you have collections of similarly-formatted rewrites, why not group them together with one particular set of rules for each? That way you could cover, for example, all incoming URLs with one subdirectory with one rule, and all incoming URLs with a single subdirectory one with another rule. If nothing else, it could help simplify viewing the .htaccess file :)
(Take everything I suggest with a massive dose of salt, I'm still getting to grips with the black magick of mod_rewrite myself)

Resources