How to Redirect www to Non-www or Non-www to www for Apache2 on Ubuntu 18.04 LTS
On Ubuntu,
Introduction:
In this article, I will guide you redirect www to Non-wwwwith Apache on Ubuntu 18.04 LTS
Prerequisites:
- One Ubuntu 18.04 LTS server that already installed Apache2. You can refer to the article as How to Install LAMP on Ubuntu 18.04 LTS.
- A fully registered domain name. This domain name has been configured DNS.
- Be sure that you have a virtual host file for your domain. This video tutorial will use /etc/apache2/sites-available/dan14.vn.conf as an example (dan14.vn – this is my domain name).
Please see the video tutorial details below to help you redirect
www to Non-www with Apache on Ubuntu 18.04 LTS:
So, redirect www to Non-www with Apache on Ubuntu 18.04 LTS that
there are 3 basic steps as follows:
- Step 1 — Enable Rewrite Module
- Step 2 — Enable .htaccess Files
- Step 3 — Configure Rewrite Module
Code templates <used to configuring>
+ DocumentRoot - add to Apache configuration
<Directory
/var/www/html>
Options Indexes
FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
+ Option 1: Redirect www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
+ Option 2: Redirect non- RewriteEngine On
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Conclusion:
In this tutorial, we already completed redirect www toNon-www with Apache on Ubuntu 18.04 LTS. If you have any questions, please
comment below. We will discuss and give the best answer. Thank you everyone.
In addition, if you have any problems with your computer, please contact us directly through the QTitHow fanpage. We will try to help and answer you as soon as possible. Thank you!
Related Article:
📂 How To Install LAMP On UBUNTU 18.04 LTS Google Cloud:
↪️ Video: How To Install LAMP On UBUNTU 18.04 LTS Google Cloud
↪️ Article:
📂 How To Install HTTPS to Secure Apache with Let's Encrypt TLS/SSL Certificates on UBUNTU 18 04LTS:
↪️ Video: How To Install SSL Certificates on UBUNTU 18 04LTS
↪️ Article: How To Install HTTPS to Secure Apache with Let's Encrypt TLS/SSL Certificates on UBUNTU 18.04LTS
You can likewise do exceptionally sharp and accommodating things that will make your site considerably more amicable to guests and the web search tools, yet a greater amount of that in the second Part of this article. wordpress err_too_many_redirects
ReplyDelete