Redirect entire site to other url with htaccess - .htaccess

I have a site which you can access with or without https rule. So, I need to make a redirect to another page. Example:
My website is: www.google.com so I can access by the moment as https://www.google.com and http://www.google.com but I need when you get into my website trough http or https way you must have to redirect to www.yahoo.com.
Besides I need the url redirection too to any subdomain or url which exists in http://www.google.com or https://www.google.com
How can I do this? I have no found alredy information about it in S.O. Thanks.

Very simple. You can use the following Redirect in your htaccess to redirect all requests from your site to the other domain
RedirectMatch 301 / http://yahoo.com/

Related

301 redirect from one domain to another but only for specific pages

We are rebuilding a website for a client from ASP to WordPress. This website will have a different domain, url structure, and file extension. I am only just getting my head around htaccess 301 redirects, and I know enough that I can't do the following:
Redirect 301 http://www.site1.com/about_us.asp https://site2.com/about/
Redirect 301 http://www.site1.com/art-specs/ https://site2.com/specs/
Redirect 301 http://www.site1.com/page/product1/ https://site2.com/product1/
There are about 12 links in total that need to be redirected, and I want to make sure that it is done right the first time as a client's SEO rankings are on the line.
Is there a variation of the above format that I could use? Or a rewrite rule that needs to be done first? Any help (and explanations) would be greatly appreciated!
After looking more into it, I realised that the htaccess file shouldn't need anything other than relative access to the original domain.
i.e. You shouldn't need to declare: http://www.site1.com/about_us.asp since the server and domain should be configured in such a way that /about_us.asp means the same thing.
So the correct answer would be to:
[1] Configure the server (in my case cPanel) by having the original domain added as an addon domain (e.g http://www.site1.com/).
[2] In the htaccess file I would add each of the 301 redirects to the htaccess file:
Redirect 301 /about_us.asp https://site2.com/about/
Redirect 301 /art-specs/ https://site2.com/specs/
Redirect 301 /page/product1/ https://site2.com/product1/
...for each redirect
[3] And finally, adding the following to the bottom of the htaccess file will catch everything else and redirect them to the home page:
RedirectMatch 301 .* https://site2.com

Redirect Old URL to New URL open cart using htaccess

I want to redirect 301 old url to new url.
my old url is;
http://www.domainname.com/special
and new url is;
http://www.domainname.com/offers
I tried this code:
redirect 301 /http://www.domainname.com/special http://www.domainname.com/offers
But still now it's not redirecting & taking me to the old URL which does'nt exist.
Try this :
Redirect 301 /special /offers
Second argument of Redirect Directive is the URL Path, it doesn't start with Scheme and hostname.
There are various ways to do this and various redirects, I've listed them below:
301 (Permanent) Redirect: Point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain:
This allows you to redirect your entire website to any other domain
Redirect 301 / http://example.com/
302 (Temporary) Redirect: Point an entire site to a different temporary URL. This is useful for SEO purposes when you have a temporary landing page and plan to switch back to your main landing page at a later date:
This allows you to redirect your entire website to any other domain
Redirect 302 / http://example.com/
Redirect index.html to a specific subfolder:
This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/
Redirect an old file to a new file path:
Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html
Redirect to a specific index page:
Provide Specific Index Page (Set the default handler)
DirectoryIndex index.html

How do I redirect a web URL using .htaccess

I want to redirect users who enter this website URL:
http://www.myWebsite.com/bananas
to:
http://www.myWebsite.com/fruits/bananas
I cant test it because I'm sending this to somebody.
I have these but I don't know for sure which one works:
RedirectMatch 301 http://www.myWebsite.com/bananas(.*) http://www.myWebsite.com/food/bananas $1
Options +FollowSymlinks
RewriteEngine on
rewriterule ^bananas(.*)$ http://www.myWebsite.com/food/bananas $1 [r=301,nc]
Please specify if you want to redirect or rewrite. The rules you are using serve different purposes and you used both in your example.
Redirect: Actually load a different site when entering the url (end up at url and content of /fruits/bananas)
Rewrite: Url stays the same but server provides rewritten content (url stays at /bananas, but show /fruits/bananas content)
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
Also it is not clear if you only want one single directory to be redirected or all files that are contained in that directory.
Checkout this as a guide: http://www.htaccessredirect.net/
I believe you are looking for
Redirect 301 /bananas http://www.myWebsite.com/fruits/bananas
The HTTP 301 stands for Moved Permanently.
I haven't tested it, though.

.htaccess Redirect 301 Issue

I am having an htaccess issue that I cannot seem to figure out.
On my site I have several pages that have /wiget/ in the url.
.com/wiget/
.com/wigeta/
.com/wigeb/
.com/wigetc/
.com/shop/wigeta/
.com/shop/wigetb/
In my htaccess file I am using the following:
Redirect 301 /wiget/ http://www.site.com/content/wiget/
Redirect 301 /wigeta/ http://www.site.com/content/wigeta/
Redirect 301 /wigetb/ http://www.site.com/content/wigetb/
Etc.
What is happening, is that every URL with /wiget/ /wigeta/ /wigetb/ in it is getting redirected incorrectly. For example, these urls:
.com/shop/wiget/ is being sent to .com/shop/content/wiget/
.com/shop/wigeta/ is being sent to .com/shop/content/wigeta/
.com/shop/wigetb/ is being sent to .com/shop/content/wigetb/
What I want is only pages that have .com/wiget/ or .com/wigeta/ or .com/wigetb/ to be redirected to their .com/content/wiget{x}/ page
I am a rookie at htaccess and I cannot drum up the solution.
So basically you want to specify that your url have to start with /wiget/
RewriteRule ^/wiget/ /content/wiget/ [L,R=301]

Redirecting bad url links from external sites with .htaccess

I have two inbound links that land on 404 pages because the links are squiffy. I have tried 301'ing these links as normal but without success, I believe because of the characters used from this external URL.
Column<u>Radiators.html
is the page suggested on this external site and
Column_Radiators.html
is the actual page.
also
Bath%3Cu%3EFiller.html
on the external site and
Bath_Filler.html
on our actual website.
How can I succesfully redirect these pages?
Simply add these lines in your .htaccess
redirect 301 /Column<u>Radiators.html /index.html
redirect 301 /Bath<u>Filler.html /index.html
Note: I use index.html as the default redirection but you can use a custom 404.

Resources