Apache 重写 URL 在 vhost.conf 中不起作用

Apache 重写 URL 在 vhost.conf 中不起作用

这是我的 vhost.conf

<VirtualHost *:80>
<files xmlrpc.php>
      order allow,deny
      deny from all
    </files>
    ServerName www.myserver.com
    ServerAlias myserver.com

    DocumentRoot /var/www/vhosts/www.myserver.com
    <Directory /var/www/vhosts/www.myserver.com>
   Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
# AllowOverride None
        #Order Allow,Deny
        #Allow from All
        #Deny from 124.43.19.230

        <IfModule mod_rewrite.c>
          RewriteEngine On
          RewriteBase /
          RewriteRule ^index\.php$ - [L]
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule . /index.php [L]

# Restrict access to PHP files from plugin and theme directories
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/file/to/exclude\.php
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/directory/to/exclude/
RewriteRule wp-content/plugins/(.*\.php)$ - [R=404,L]
RewriteCond %{REQUEST_URI} !^/wp-content/themes/file/to/exclude\.php
RewriteCond %{REQUEST_URI} !^/wp-content/themes/directory/to/exclude/
RewriteRule wp-content/themes/(.*\.php)$ - [R=404,L]
        </IfModule>
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/file/to/exclude\.php
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/directory/to/exclude/
RewriteRule wp-content/plugins/(.*\.php)$ - [R=404,L]
RewriteCond %{REQUEST_URI} !^/wp-content/themes/file/to/exclude\.php
RewriteCond %{REQUEST_URI} !^/wp-content/themes/directory/to/exclude/
RewriteRule wp-content/themes/(.*\.php)$ - [R=404,L]
</Directory>
</VirtualHost>

当我在浏览器中输入 www.myserver.com 时,它会转到我的根目录并获取 index.php

但是当我输入 myserver.com 时,它会转到默认的 Apache 网页 (index.html) 加载

所以我添加了此行以进行重写

</VirtualHost>
 <VirtualHost *:80>
      ServerName myswever.com
      ServerAlias *.myswever.com
      Redirect permanent / https://www.myswever.com/
    </VirtualHost>

但它不起作用这是一个 word-press 网站如何重新连接 url

当输入某些 myswever.com 时,它应该加载 www.myswever.com

答案1

这可能只是一个打字错误吗?

      ServerName myswever.com
      ServerAlias *.myswever.com
      Redirect permanent / https://www.myswever.com/

米斯韦弗

否则检查是否有其他配置处于活动状态,使用

a2ensite

停用

a2dissite

还要检查是否有另一个配置在下创建此配置

/etc/apache2/*.conf
/etc/apache2/sites-enabled/*

顺便说一下,您的 vhost.conf 用于端口 80,即纯 HTTP,您的重定向将转到 HTTPS,端口 443。如果您不激活 mod_ssl 并为端口 443 添加/扩展 vhost 配置,则 https 重定向将不起作用。

您的标准 Apache 页面显示您仍有一个活动的默认配置,您可以删除它,它应该在文件夹中/etc/apache2/sites-available/*,如果它处于活动状态,则会有一个指向/etc/apache2/sites-enabled/*此配置的符号链接。上述两个命令均显示所有活动或非活动配置,它们只会删除此配置的符号链接/etc/apache2/sites-enabled/*

希望有帮助,s1mmel

相关内容