301 redirect entire website to a single page - .htaccess

I have a website that I would like to implement a 301 redirect for an entire site (every page on the website) to a single page. Basically I have an old blog and I want to 301 redirect every page on that blog to our Facebook page instead.
When I search google I get the response to do it this way:
Redirect 301 / https://www.facebook.com/whatever
This works, however the problem I am running into is if someone types in a subfolder of the website such as: www.oldwebsite.com/subfolder it will redirect to https://www.facebook.com/whateversubfolder which is not what I need.
I need every possible page on oldwebsite.com to redirect to the single page https://www.facebook.com/whatever. Thanks!

You want to use RedirectMatch:
RedirectMatch 301 ^(.*)$ https://www.facebook.com/whatever

Related

301 redirects specific pages with get parameters and non-specified pages

I have my old website old.com and my new website new.com. I want to create 301 redirects in the .htaccess for some specific pages and some generic 301 redirects as well.
Get parameter redirects:
old.com/a/test?u=blah redirect to new.com/a/test?u=blah
old.com/a/test redirect to new.com/a/test
old.com/a/test.php?u=blah redirect to new.com/a/test?u=blah
As you can see the only thing that changed was the domain name. How can I redirect users to the new domain but also keep their get parameter the same. So regardless of what u=, it forwards the u= parameter to the new URL. Of course if there is no u=, it still redirects to the page (as per second example)
Get parameter without putting get parameter
old.com/a/foo?u=blah redirect to new.com/a/foo
old.com/a/foo redirect to new.com/a/foo
old.com/a/foo.php?u=blah redirect to new.com/a/foo
As you can see, it directs to the new domain but does not carry the u= parameter. Same applies for the second example.
Redirect Directory
old.com/blog redirect to new.com/blog
old.com/blog/23452/how-to-tie-a-tie redirect to new.com/blog
If the site is in the blog directory, regardless of what comes after the blog directory in the URL, it always redirects back to new.com/blog
I am unsure on how to do these types of specific redirects. I only understand how to direct a specific URL like so Redirect 301 old.com https://new.com

Need help redirecting one website URL to another with apache2 and .htaccess

I have two domains - https://hosting.opensimcity.org, and http://paradigm.pocketmud.com and I want to redirect the latter to the former. That is, when someone connects to http://paradigm.pocketmud.com I want it to redirect to https://hosting.opensimcity.org/paradigm
Any tips on doing this in my .htaccess file?
Just try the following htaccess redirect code:
Redirect 301 / https://hosting.opensimcity.org/paradigm
This 301 redirect response notifies the search engines that the page has moved permanently from the old URL to the new URL. The search engines also transfer the old URL page rank to the new URL.

Link in Google search results is not redirected to expected page as per .htaccess

I originally asked a .htaccess question here and got some awesome help, which worked a treat. Basically, I'm trying to redirect pages from an old site to a new site, and have managed to make most things work. However, there's a couple of links in Google's search results that aren't redirecting properly, and I believe this is because they're all www and the new site redirects to non-www. For example, a link like this in the search engine results:
www.example.com/Expertise/ProductTesting
Should go to:
example.com/services/product-testing
But instead goes to:
example.com/services/ProductTesting
So for some reason the last part of the URL isn't changing. Here's how that line looks in my .htaccess:
RedirectMatch 301 ^/Expertise/ProductTesting/?$ /services/product-testing/
If I type the address in manually and drop the www, it redirects as it should.
Thanks in advance!
Taking your previous question into consideration, you must put your new rule before the one that is matching everything: RedirectMatch 301 ^/Expertise/(.*)$ /services/$1.
Also, you'll maybe have to clear your browser's cache before trying again (or try it with another browser).
Your rules should look like this
RedirectMatch 301 ^/Expertise/QuantitativeResearch/?$ /services/quantitative-research/
RedirectMatch 301 ^/Expertise/ProductTesting/?$ /services/product-testing/
RedirectMatch 301 ^/Expertise/(.*)$ /services/$1

htaccess Redirect URL of Subdirectories managed through CMS

All the urls of our site are written www.mydomain.com/sub1/cms/pagename
Through the CMS we can specify pagename
sub1 and cms are not actually directories on the server.
We need to change the pagenames to be more SEO friendly, but we still want any traffic to the old pagename to direct to the new one.
I have tried making an .htaccess file specifying:
Redirect 301 /sub1/cms/oldpagename mydomain.com/sub1/cms/newpagename
but it does not work.
I have been successful with:
Redirect 301 /oldpagename mydomain.com/sub1/cms/newpagename
Can this be done somehow through .htaccess?
First, make sure your 301 redirect rules for redirect use a full url including the http:// portion.
Redirect 301 /sub1/cms/oldpagename http://mydomain.com/sub1/cms/newpagename
Second, it sounds to me like your CMS has put a rewrite rule in place to handle the /sub1/cms/pagename style urls. If this rule comes before your redirect, your redirect will never get triggered. Try moving your redirect to the top of the .htaccess file.

htaccess redirect with 301 from a folder that no longer exists

I've read a number of websites and they all say something different. On my friends site his blog was previously www.bellastairs.com/news now its just the main page so www.bellastairs.com.
What is the easiest way to redirect any hits that no longer exist trying to get to news to redirect to the homepage?
For example google searching for glass stairs miami.
He's the second link but its now dead. Is there an easy way to change the htaccess to redirect that permanently to his homepage?
Put this in the htaccess file in your document root:
RedirectMatch 301 ^/news /

Resources