尝试访问 http 时添加尾部正斜杠以进行重定向

尝试访问 http 时添加尾部正斜杠以进行重定向

我正在尝试在不在服务器索引中时进行重定向,以转到我的网站的 https 非 www 版本。目前,当输入http://example.com/login重定向转到时https://example.comlogin,这显然会给我一个错误。

这是我的default-ssl.conf文件:

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
            ServerAdmin [email protected]

            DocumentRoot /var/www/html
            RewriteEngine On

            # Remove trailing slash from non-filepath urls
            RewriteCond %{REQUEST_URI} /(.+)/$
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ https://example.com/%1 [R=301,L]

            # Include trailing slash on directory
            RewriteCond %{REQUEST_URI} !(.+)/$
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^(.+)$ https://example.com/$1/ [R=301,L]

            # Force HTTPS and remove WWW
            RewriteCond %{HTTP_HOST} ^www\.(.*)$ [OR,NC]
            RewriteCond %{HTTPS} off
            RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

我的也有.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.php -f
  RewriteRule ^(.*)$ $1.php
</IfModule>

我的example.com.conf

<VirtualHost *:80>
  ServerAdmin [email protected]
  ServerName example.com
  ServerAlias example.com
  DocumentRoot /var/www/example.com/html
  ErrorLog /var/www/example.com/logs/error.log
  CustomLog /var/www/example.com/logs/access.log combined
  <Directory /var/www/example.com/>
      Options FollowSymLinks
      AllowOverride All
      Require all granted
  </Directory>
</VirtualHost>

<VirtualHost *:443>
  ServerAdmin [email protected]
  ServerName example.com
  ServerAlias example.com
  DocumentRoot /var/www/example.com/html
  ErrorLog /var/www/example.com/logs/error.log
  CustomLog /var/www/example.com/logs/access.log combined
  <Directory /var/www/example.com/>
      Options FollowSymLinks
      AllowOverride All
      Require all granted
  </Directory>
</VirtualHost>

相关内容