首页 > 解决方案 > 我正在尝试将 /example 重定向到 Apache 的 httpd.conf 中的 example.html,但它不起作用

问题描述

这是我试图在 httpd.conf 中应用的代码:

<VirtualHost *:80>
    ServerName www.test.com
    ServerAlias www.test.com

    DocumentRoot /home/test_com
    ErrorLog /home/logs/apache/www_test/www.test.com-error_log
    CustomLog /home/logs/apache/www_test/www.test.com.-access_log common env=!do_not_log

    # https redirect
    RewriteEngine On

    RewriteCond %{HTTP_HOST} www.test.com
    RewriteCond %{REQUEST_URI} /example
    RewriteRule . https://www.test.com/example.html [R=303,L]

    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}

    <Directory "/home/test_com/">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

</VirtualHost>

应用代码并重新启动 apache 后,当我转到 /example 时,我得到一个 404 not found 响应。

当我在 ( https://htaccess.madewithlove.be )测试 htaccess 时,输出是我想要的https://www.test.com/example.html 。我想知道问题是什么。

标签: apache.htaccessredirect

解决方案


RewriteRule 的右侧部分是目标文件,尝试更改:

RewriteCond %{REQUEST_URI} /example

至 :

 RewriteCond %{REQUEST_URI} /example.html

推荐阅读