在apache mod_rewrite中的一个条件上添加尾部斜杠

时间:2014-04-25 19:38:45

标签: apache mod-rewrite apache2 trailing-slash

我知道这是一个常见的问题,我知道有一个简单的解决方案,但我无法获得我在网上找到的解决方案来处理我的情况。

我有一个地址:

https://localhost/cms

但是,当访问者访问此地址时,apache无法找到该资源,但如果访问者访问该地址:

https://localhost/cms/

正如预期的那样有效。所以,为了解决这个问题,我试图创建一个mod重写条件,但我遇到了一些麻烦。到目前为止,这是我的conf文件:

<VirtualHost *:443>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(.*)/cms
    RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1/ [L,R=301]
    ProxyPreserveHost on
    ProxyRequests off
    ProxyPass /cms/ http://localhost:9000/cms/
    ProxyPassReverse /cms/ http://localhost:9000/cms/
</VirtualHost>

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

所以,我通过使用ReverseProxy来解决这个问题,这里是更新的配置文件:

<VirtualHost *:443>
    ProxyPreserveHost on
    ProxyRequests off

    ProxyPass /cms/ http://localhost:9000/cms/
    ProxyPassReverse /cms/ http://localhost:9000/cms/

    ProxyPass /cms http://localhost:9000/cms/
    ProxyPassReverse /cms http://localhost:9000/cms/

</VirtualHost>