Reputation: 100
I have read many answers but nothing seems to work for me. I want to redirect non www domain to www, but it is not happening.
My .htaccess file in /home/ashish/mywebsite where my website code lies:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^getechready.com [NC]
RewriteRule ^(.*)$ http://www.getechready.com/$1 [L,R=301]
mywebsite.conf file in /etc/apache2/sites-available:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/ashish/mywebsite/static
<Directory /home/ashish/mywebsite/static>
Require all granted
</Directory>
Alias /media /home/ashish/mywebsite/media
<Directory /home/ashish/mywebsite/media>
Require all granted
</Directory>
<Directory /home/ashish/mywebsite/mywebsite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/ashish/mywebsite>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
WSGIScriptAlias / /home/ashish/mywebsite/mywebsite/wsgi.py
WSGIDaemonProcess django_app python-path=/home/ashish/mywebsite python->
WSGIProcessGroup django_app
</VirtualHost>
apache2.conf in /etc/apache2 :
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
when I write some gibberish on .htacess file website gives 500 error. so .htaccess files is being read but when I do curl -I getechready.com, it shows url not resolved and redirection aslo does not happen in browser.
I am using Python 3.8 and django 3.1.
Note: my document root is /var/www/html but my website code lies in /ashish/home/mywebsite , where I have place .htacess file
Please let me know in case any other data required.
Upvotes: 0
Views: 68
Reputation: 100
I did not get any answer suitable for me from apache end,
So because I am using Django , what I did is added : PREPEND_WWW = True
in settings.py file, just make sure you have 'django.middleware.common.CommonMiddleware',
in your middlewares and remember to remove all the rules from .htaccess file. worked for me
Upvotes: 1