Redirects with .htaccess
Route traffic with smart redirects.
The most common use case for `.htaccess` is to re-write URLs with `mod_rewrite`. You can direct requests to a subdirectory, or specific domain, prettify URLs by omitting file endings, force https and much more.
Redirect all requests to https
Force https! There is no need for your application to be reached over a non-secure connection. Use .htaccess to redirect all http:// requests over to https://. This is how:
RewriteEngine On RewriteCond %{HTTP:X-Forwarded-Proto} !=https RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,N]raw
Order matters. This rule should be one of first rules, so right on top of your htaccess file Please also note the X-Header part. Other code snippets you find elsewhere might not work here. This is because we are running our Apache behind a set of load-balancers. They are performing the HTTPS encryption and not Apache. Many CMS and frameworks are already offering convenient settings and configurations for this.
Redirect all requests to the primary domain
Once you've added a custom domain you may want to prevent requests to your test domain. The example below shows how to set up a domain based redirect in your .htaccess file.
# From test domain to your domain RewriteEngine On RewriteCond %{HTTP_HOST} ^.*\.frb\.io$ [NC] RewriteRule .* https://www.your-domain.example%{REQUEST_URI} [r=301,L,N]raw
A CMS will have it's own options for that. If you don't use a redirect, make sure to at least set the "canonical URL" to be on your primary custom domain so that that search engines know that there is only one content.