301 Redirects with S3 - .htaccess

I am trying to replace a few Redirects that are currently located in a .htaccess file to an S3 bucket(s). I am having trouble with the custom redirects to a different domain.
For example, one of my re-directs looks like this:
Redirect 301 /site https://newwebsite.com
I have set the custom routing rule as, but its not doing the redirect, its just replacing "site" with "https://newwebsite.com", ie bucket-name-amazonaws.com/https://newwebsite.com
<?xml version="1.0"?>
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>site</KeyPrefixEquals>
</Condition>
<Redirect>
<HostName>newwebsite</HostName>
<Protocol>https</Protocol>
<ReplaceKeyPrefixWith></ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>

User error....I had initially set it up wrong and it was cached.

Related

Redirect full URL to another full URL?

I want to 301 redirect from https://whatever-12345.de/something.html to https://whatever.de/something.html using a .htaccess file. I could not find a working example and this does not work:
redirect 301 https://whatever-12345.de/something.html https://whatever.de/something.html
Ideas?
First alternative, redirect a specific page called /sourcepage.html to another URL:
Redirect 301 /sourcepage.html http://Exampledomain.com/
Second alternative, redirect the whole domain to another URL:
Redirect 301 / http://www.Exampledomain.com/
And last, redirect one file to another file, locally, in the same domain:
Redirect 301 /old/path/oldpage.html http://www.currentdomain.com/new/path/newpage.html
PHP:
Now, by this method, you need FTP access to edit files in your server as well. We will create a PHP file named old.php. Here’s how this file will look like:
<?php
header("Location: http://www.mynewwebsite.com/blog/");
?>
This way, whenever we access this specific PHP file, the user will be redirected to our destination site.
We can also use a more complete PHP file, specifying that this is a 301 redirect (permanent). In this case, the PHP file would look like:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.mynewwebsite.com/blog/");
?>

How redirect comma separated url with htaccess?

There are 2 different URLs https://maldivesresorts.com.au/package/vakarufalhi-island-resort-all-meals-drinks/ and https://maldivesresorts.com.au/package/vakarufalhi-island-resort-all-meals-drinks/ but while SEO audit I found the wrong url and it is showing like https://maldivesresorts.com.au/luxury-resorts-study-vakarufalhi-maldives-resort/,https://maldivesresorts.com.au/package/vakarufalhi-island-resort-all-meals-drinks/,here so I want to redirect the wrong url to another page.
So it should be redirect
to /hot-deals.
Here is my htaccess code but it doesn't seems working
RewriteEngine On
redirect /luxury-resorts-study-vakarufalhi-maldives-resort/,https://maldivesresorts.com.au/package/vakarufalhi-island-resort-all-meals-drinks/,here /hot-deals
This is how redirects work:
ref: https://www.semrush.com/blog/htaccess-redirect/
So you should be doing:
RewriteEngine On
redirect 301 /luxury-resorts-study-vakarufalhi-maldives-resort/ /hot-deals
redirect 301 /package/vakarufalhi-island-resort-all-meals-drinks/ /hot-deals
However, you look like you're redirecting folders rather than files so you should simply look at this question which your question appears to be a duplicate of.

Redirect custom URLs via htaccess

I have my own domain:
http://cesarferreira.com
and I wanna make
http://cesarferreira.com/github
point to
https://github.com/cesarferreira
Without having to make a /github/ folder with an index.html with a redirect for each page I own (facebook, twitter, pinterest, etc)
Is there a way like for example htaccess catchig *.com/github and pointing to a given static url?
Thanks a lot
If your document root serves -
http://cesarferreira.com
you can put a redirect in .htaccess like -
Redirect /github https://github.com/cesarferreira
Take a look at URL rewriter 'http://httpd.apache.org/docs/2.0/misc/rewriteguide.html'. That should be able to do everything you want and more.
As long as it is enabled in apache then you can use it in .htaccess files also.
You can use mod_alias:
Redirect 301 /github https://github.com/cesarferreira
Or if you only want github to point only to the folder:
RedirectMatch 301 ^/github https://github.com/cesarferreira
You can put that in the htaccess file of your document root.

Which .htaccess file should I be using for 301 redirects?

This is one of those super-simple questions that I can't seem to google an answer for, so apologies in advance.
When I ftp into my (shared) server, I have a file structure like this:
Root (/)
/public_html
/newdomain.com
I had an old website that lived in /public_html, it had heaps of content and excellent SEO. We changed our name and our domain (which lives in /newdomain.com, a folder inside /public_html), and set 301 redirects from all the old content to the new website.
I tried doing this myself, but it didn't work at all, so I got my host's techsupport to do it for me. There are several .htaccess files on my server though, and I don't know which ones are actually effective and which aren't.
Root has its own .htaccess file
public_html has its own .htaccess file
/newdomain.com DOESN'T have its own .htaccess file
Redirection 1 (currently is in both root and public_html's .htaccess files, and works)
I want to redirect http://olddomain.com/whatever -> http://newdomain.com/whatever (I've currently got each individual page doing its own separate 301 versus a single rule doing this). Achieved with Redirect 301 /article-name-here/ http://www.newsite.com/article-name-here/
Redirection 2 (currently is in both root and public_html's .htaccess files, and doesn't work).
I also want to do some internal redirections of http://newdomain.com/oldpage.html -> http://newdomain.com/newpage.html. I've tried redirection public_html's .htaccess file like so:
Redirect 301 http://newsite.com/badpage.html http://newsite.com/goodpage.html
But it's not working. Do I need to set up a new .htaccess in the newsite.com folder on my server? Or am I just completely missing the mark here?
Redirection 1
To redirect everything, just remove the article name:
Redirect 301 / http://www.newsite.com/
Or if you don't want to redirect the root (i.e. requests for /), then:
RedirectMatch 301 ^/(.+)$ http://www.newsite.com/$1
Redirection 2
If the /newdomain directory is the document root for http://newdomain.com/, then you'll need to create a new htaccess file there and include:
Redirect 301 /badpage.html /goodpage.html

htaccess to redirect url with params

I have to redirect a url to another url with all its parameters using htaccess.
My incoming url will be something like this:
www.mydomain.com/book-it.jsp?id=3&var1=values&var2=value2...
and I want to get it in PHP (book-it.php) as something like this (with all its parameters):
www.mydomain.com/book-it.php?id=3&var1=values&var2=value2...
I was using JSP and from now on moving to PHP and we need to use same URL since this url is already published with my application and I can't change that now. I need to get that url and parameters to another file.
You have 2 main approaches:
1) Using Redirect directive:
Redirect 301 /book-it.jsp http://www.mydomain.com/book-it.php
2) Using mod_rewrite module (this needs to be placed in .htaccess in website root folder. If placed in Apache config file (inside <VirtualHost>, for example) the rules need to be modified slightly):
RewriteEngine On
RewriteBase /
RewriteRule ^book-it\.jsp$ http://www.mydomain.com/book-it.php [QSA,NC,R=301,L]
Both of them will preserve query string.

Resources