Vue: How to force www - .htaccess

Hello,
I have a website in Vue Cli 4. Is there a way to always have www like this on the web? Just redirect non-www to www
I have:
https://website.cz
I want:
https://www.website.cz
can this be done purely via VUE or is there no other option than htaccess? Or how to configure htaccess to work in development mode (npm serve) too?

.htaccess try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^website.cz [NC]
RewriteRule ^(.*)$ https://www.website.cz/$1 [L,R=301]
see redirect https - www

Related

How to set up 301 redirect to a new domain

I have a domain for which I would like to set up both a www and non-www redirect to https://newdomain.com.
So olddomain.com and www.olddomain.com should go to https://shinynewdomain.com.
#redirect http non-www to https://www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$
RewriteRule (.*) https://www.newdomain.com/$1 [R=301,L]
#redirect https non-www to www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^olddomain\.com$
RewriteRule (.*) https://newdomain.com/$1 [R=301,L]
This is the code I'm using, and it sends me to a domain parking page at my registrar instead of the new domain at a different host.
Am I doing anything wrong?
There are several ways you can do the redirection of your old website to your new website. If your website is made using wordpress then it will be more easy to achieve 301 redirections.
Method 1:
In Wordpress, what you can do is install the plugin Simple 301 Redirect.
Setup the plugin as you like.
Then you will find options in Settings after activating it.
Method 2
Another is using some code line in the .htaccess file.
In the web directory settings, you will find the access of .htaccess file.
Open the file in the editor and use the code below.
To redirect a single page: Redirect 301 /old-file.html http://www.example.com/new-file.html
To redirect to a new website: Redirect 301 / http://www.new-example.com/

Force HTTPS using Redirect in .htaccess

I've recently tried to force HTTPS on my website by using various directives contained in mod_rewrite. However it didn't workout very well and now it's recommented to use the Redirect directive from mod_alias. I've got everything in a subfolder and I wrote:
Redirect "/folder/" "https://mywebsite.org/folder/"
in my .htaccess file, but it keeps giving me the ERR_TOO_MANY_REDIRECTS error.
This code in .htaccess will redirect http://example.com to https://example.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect all webpages to www with .htaccess

I've been trying to redirect my subdomain pages to force them to be at www.
The thing is, if I try example.example.com it will perfectly redirect to www.example.example.com, in the other hand, if I try example.example.com/whatever.html it won't redirect. My .htaccess file looks something like this:
RewriteEngine On
#subdomain non-www to www
RewriteCond %{HTTP_HOST} ^example.example.com$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]
Any ideas? Thanks guys!
Try removing the $ from the RewriteCond line.

Remove www from the url

Does anyone have the setttings from the .htaccess file to remove www from my url?
http://example.com
I've tried using some of the settings in the internet but it gives me a redirect loop. I need something that prevents a redirect loop.
this would really help me. thank you
You can put this code in your htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
If you're still having a redirect loop:
you have maybe another script that redirects non-www to www
old rule still in browser's cache (try cleaning cache or with another browser)

htaccess - get all non-www traffic redirected to the www

Can anyone suggest how I get non www traffic to redirect to the www version of a website using the htaccess file - I know I have one created in my root directory but cannot be sure what to put.. any ideas
Relatively easily.
Match anything that does not begin with 'www.' and then redirect to the 'www.' version:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Resources