将vhost.conf转换为.htaccess

时间:2013-12-02 11:05:07

标签: apache .htaccess vhosts

大多数人似乎都在考虑将.htaccess转换为vhost.conf。我反过来需要的东西。我有一个现有的vhost.conf文件,看起来像这样....

ServerAlias base1.mydomain.com
ServerAlias base2.mydomain.com
ServerAlias base3.mydomain.com
ServerAlias www.mysite1.co.uk
ServerAlias www.mysite2.co.uk


    RewriteEngine on

    RewriteMap lowercase int:tolower
    RewriteCond %{REQUEST_URI} !^/images/
    RewriteCond %{REQUEST_URI} !^/code/
    RewriteCond %{REQUEST_URI} !^/php/
    RewriteCond %{REQUEST_URI} !^/php-bin/
    RewriteCond %{REQUEST_URI} !^/syles/
    RewriteCond %{REQUEST_URI} !^/js/
    RewriteCond %{REQUEST_URI} !^/jquery/
    RewriteRule ^/(.*)$ /var/www/vhosts/mydomain.com/subdomains/${lowercase:%{SERVER_NAME}}/htdocs/$1

    Alias /scripts/ "/var/www/vhosts/mydomain.com/subdomains/ysite/V4_0_1/scripts/"
    Alias /php/ "/var/www/vhosts/mydomain.com/subdomains/ysite/V4_0_1/php-bin/"

<Files ~ (\.phtml)>
            SetHandler fcgid-script
            FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .phtml
            Options +ExecCGI
            allow from all
    </Files>

    <Files ~ (\.php)>
            SetHandler fcgid-script
            FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .php
            Options +ExecCGI
            allow from all
    </Files>

    <Files ~ (\.php4)>
            SetHandler fcgid-script
            FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .php4
            Options +ExecCGI
            allow from all
    </Files>

Alias /php-bin/ "/var/www/vhosts/mydomain.com/subdomains/ysite/V4_5/php-bin/"
Alias /js/ "/var/www/vhosts/mydomain.com/subdomains/ysite/V4_5/js/"
Alias /css/ "/var/www/vhosts/mydomain.com/subdomains/ysite/V4_5/styles/"
Alias /jquery/ "/var/www/vhosts/mydomain.com/subdomains/ysite/V4_5/jquery/"

我正在尝试将其转换为.htaccess文件。从顶部开始,与serveralias相同的.htaccess命令是什么?

1 个答案:

答案 0 :(得分:2)

并非vhost.conf的所有内容都可以复制到.htaccess,因为.htaccess中不允许所有指令。

您可以将此代码放在DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine on

RewriteCond ${HOST_NAME} [A-Z]
RewriteCond %{REQUEST_URI} !^/(images|code|php|php-bin|styles|js|jquery)/
RewriteRule ^(.*)$ http://${lowercase:%{HOST_NAME}}/$1 [L,R]

<Files ~ (\.phtml)>
        SetHandler fcgid-script
        FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .phtml
        Options +ExecCGI
        allow from all
</Files>

<Files ~ (\.php)>
        SetHandler fcgid-script
        FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .php
        Options +ExecCGI
        allow from all
</Files>

<Files ~ (\.php4)>
        SetHandler fcgid-script
        FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .php4
        Options +ExecCGI
        allow from all
</Files>