【发布时间】:2021-02-26 17:25:06
【问题描述】:
我已经阅读了很多答案,但似乎没有什么对我有用。我想将非 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-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 在 /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>
当我在 .htacess 文件网站上写一些乱码时,会出现 500 错误。所以正在读取 .htaccess 文件,但是当我执行 curl -I getechready.com 时,它显示 url 未解析并且重定向也不会在浏览器中发生。
我正在使用 Python 3.8 和 django 3.1。
注意:我的文档根目录是 /var/www/html 但我的网站代码位于 /ashish/home/mywebsite ,我放置 .htacess 文件的地方
如果需要任何其他数据,请告诉我。
【问题讨论】:
-
尝试清除浏览器缓存。
-
@AmitVerma 我做过,甚至多次运行'sudo service apache2 restart',但没有工作,我基本上是在做'curl -I getechready.com',它应该给出301,但它给出了URL无法解决
-
“当我做
curl -I getechready.com时,它显示url未解析” - 如果请求没有“解析”那么它甚至没有到达您的服务器或服务器不接受请求?跨度> -
@MrWhite 是的,这就是问题所在,我什至无法使用问题中提到的方法将请求重定向到我的服务器
标签: .htaccess redirect url-rewriting cloud apache2