服务器没有读取htaccess文件并且重定向不起作用

问题描述 投票:0回答:1

我的网站没有读取htaccess文件。即使我在顶部添加Deny from all,该网站加载正常。

权限是644.我在服务器上运行了许多站点,因此Apache设置正确。

这是我的虚拟主机配置:

<VirtualHost 12.34.56.78:80>
     ServerAdmin [email protected]
     ServerName example.com
     ServerAlias www.example.com
     DocumentRoot /srv/www/example.com/public_html/

    <Directory /srv/www/example.com/public_html/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

     ErrorLog /srv/www/example.com/logs/error.log
     CustomLog /srv/www/example.com/logs/access.log combined

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =www.example.com [OR]
    RewriteCond %{SERVER_NAME} =example.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

这是我添加到.htaccess文件以将www重定向到非www:

RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
RewriteRule (.*) https://%2%{REQUEST_URI} [L,R=301]

我尝试将它添加到虚拟主机,但它仍然没有重定向。

apache .htaccess mod-rewrite virtualhost lets-encrypt
1个回答
0
投票

在使用Let's Encrypt发出SSL证书后,我注意到它为端口443创建了一个重复的conf文件:

  • /etc/apache2/sites-available/example.com.conf
  • /etc/apache2/sites-available/example.com-le-ssl.conf <IfModule mod_ssl.c> <VirtualHost 12.34.56.78:443> ServerAdmin [email protected] ServerName example.com ServerAlias www.example.com DocumentRoot /srv/www/example.com/public_html/ <Directory /srv/www/example.com/public_html/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog /srv/www/example.com/logs/error.log CustomLog /srv/www/example.com/logs/access.log combined Include /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> </IfModule>

在LE之前,原来的example.com.conf没有AllowOverride All指令。所以我假设发生的事情是内容重复,然后我只改变了原来的内容。

© www.soinside.com 2019 - 2024. All rights reserved.