Skip to content

Instantly share code, notes, and snippets.

@nasirkhan
Created November 8, 2019 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasirkhan/376ecd163b57c84f68c750d1ab81f6f8 to your computer and use it in GitHub Desktop.
Save nasirkhan/376ecd163b57c84f68c750d1ab81f6f8 to your computer and use it in GitHub Desktop.
Redirect www to non www domain
## Virtual Host Config
```
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName matholympiad.org.bd
ServerAlias www.matholympiad.org.bd
DocumentRoot /var/www/html/matholympiad.org.bd/
<Directory />
AllowOverride All
</Directory>
<Directory /var/www/html/matholympiad.org.bd/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
ErrorLog /var/log/apache2/matholympiad.org.bd-error.log
LogLevel error
CustomLog /var/log/apache2/matholympiad.org.bd-access.log combined
SSLCertificateFile /etc/letsencrypt/live/matholympiad.org.bd/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/matholympiad.org.bd/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
```
## .htaccess config
```
#redirect www to website root
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment