从非www重定向到不工作于.htaccess的www

从非www重定向到不工作于.htaccess的www,.htaccess,redirect,url-rewriting,cloud,apache2,.htaccess,Redirect,Url Rewriting,Cloud,Apache2,我读了很多答案,但似乎没有什么对我有用。我想将非www域重定向到www,但它没有发生 我的.htaccess文件位于/home/ashish/mywebsite中,我的网站代码位于: RewriteEngine On RewriteCond %{HTTP_HOST} ^getechready.com [NC] RewriteRule ^(.*)$ http://www.getechready.com/$1 [L,R=301] mywebsite.conf文件在/etc/apache2/site

我读了很多答案,但似乎没有什么对我有用。我想将非www域重定向到www,但它没有发生

我的.htaccess文件位于/home/ashish/mywebsite中,我的网站代码位于:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^getechready.com [NC]
RewriteRule ^(.*)$ http://www.getechready.com/$1 [L,R=301]
mywebsite.conf文件在/etc/apache2/sites中提供:

    <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>

服务器管理员webmaster@localhost
DocumentRoot/var/www/html
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
别名/static/home/ashish/mywebsite/static
要求所有授权
别名/media/home/ashish/mywebsite/media
要求所有授权
要求所有授权
选项索引跟随符号链接
允许超越所有
要求所有授权
WSGIScriptAlias//home/ashish/mywebsite/mywebsite/wsgi.py
WSGIDaemonProcess django_应用程序python path=/home/ashish/mywebsite python->
WSGIProcessGroup django_应用程序
apache2.confin/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>

选项如下符号链接
不允许超限
要求全部拒绝
不允许超限
要求所有授权
AccessFileName.htaccess
要求全部拒绝
当我在.htacess文件上写一些胡言乱语时,网站给出了500个错误。所以,正在读取.htaccess文件,但当我执行curl-I getechready.com时,它显示url未解析,并且在浏览器中也不会发生重定向

我正在使用Python3.8和Django3.1

注意:我的文档根目录是/var/www/html,但我的网站代码位于/ashish/home/mywebsite中,我有place.htacess文件


如果需要任何其他数据,请告诉我。

我没有从apache end得到任何适合我的答案,
因此,因为我使用的是Django,所以我添加了:
PREPEND_WWW=True
在settings.py文件中,只需确保您的中间件中有
'Django.middleware.common.CommonMiddleware',
,并记住从.htaccess文件中删除所有规则。为我工作

尝试清除浏览器缓存。@AmitVerma我做过,甚至多次运行'sudo service apache2 restart',但没有工作,我基本上做'curl-I getechready.com',它应该给301,但它给URL无法解析“当我做
curl-I getechready.com
,它显示URL未解析”-如果请求没有“解析”那么它甚至没有到达您的服务器,或者服务器不接受请求?@MrWhite是的,这就是问题所在,我无法使用上述方法将请求重定向到我的服务器