简体   繁体   English

.htaccess中的虚拟主机

[英]Virtual Host in .htaccess

I would like to set up Polr Project , which is essentially a self-hosted URL shortener, on my hosting. 我想在托管上设置Polr Project ,它实际上是一个自托管的URL缩短器。 In the installation guide it says that I need to set up a virtual host in httpd-vhosts.conf . 安装指南中,它说我需要在httpd-vhosts.conf设置一个虚拟主机。 I don't have access to that file so I've got no idea on how to get it to work. 我没有访问该文件的权限,所以我不知道如何使它工作。 I have seen some blog posts about how to do something like this but it doesn't seem to help. 我看过一些博客文章,介绍如何做这样的事情,但这似乎无济于事。

Virtual Host Snippet: 虚拟主机代码段:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias example.com

    DocumentRoot "/var/www/polr/public"
    <Directory "/var/www/polr/public">
        Require all granted
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

I have tried this (but it failed): 我已经尝试过了(但是失败了):

RewriteCond %{HTTP_HOST} MY_DOMAIN.com
RewriteCond %{REQUEST_URI} !^/public
RewriteRule ^(.*)$ public/$1 [L]

Thanks in advance. 提前致谢。

You cannot setup a virtual host in .htaccess, as can be seen from the <VirtualHost> directive <VirtualHost>指令可以看出,您无法在.htaccess中设置虚拟主机。

Context: server config 上下文:服务器配置

But there's also no need to setup a virtual host, since your web hosting provider already did so. 但是,由于您的Web托管提供商已经设置了虚拟主机,因此也无需设置虚拟主机。

You need only to install Polr in the document root as described and you're done. 您只需要按照所述在文档根目录中安装Polr,就可以完成。

The rewrite rule can be simplified to 重写规则可以简化为

RewriteRule !^public$ /public%{REQUEST_URI} [L]

If you have installed it in some subdirectory, eg polr , the rule would be 如果已将其安装在某些子目录(例如polr ,则规则为

RewriteRule !^polr/public$ /polr/public%{REQUEST_URI} [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM