2012-04-16 28 views
9

Tôi đang cố thêm các quy tắc mod_rewrite vào cấu hình vhost nhưng nó không hoạt động. Đối với trang web "mysite.com", tôi muốn chuyển hướng "/ webmedia /" vào trang chủ.mod_rewrite trong cấu hình vhosts

Dưới đây là những gì tôi có:

<VirtualHost 192.168.100.142:80> 
    ServerAdmin [email protected] 
    DocumentRoot /home/drupal_1 
    ServerName mysite.com 
    ServerAlias www.mysite.com 
    Alias /movies /home/movies/ 
    ErrorLog /var/log/httpd/mysite.com_err_log 
     CustomLog /var/log/httpd/mysite.com_log special 
    <Directory /home/drupal_1> 
     Options FollowSymLinks Includes ExecCGI 
       AllowOverride All 
       DirectoryIndex index.html index.htm index.php 

     # Rewrite Rules ##################### 
     RewriteEngine On 
     RewriteRule ^/webmedia/(.*)/[R=301,L] 
     # end Rewrite Rules ################# 

    </Directory> 
    <Directory /home/movies> 
     Options FollowSymLinks Includes ExecCGI 
       AllowOverride All 
       DirectoryIndex index.html index.htm index.php 
    </Directory> 

</VirtualHost> 
+0

Tại sao không di chuyển quy tắc của bạn sang tệp '.htaccess'? Nó sẽ dễ quản lý hơn nhiều vì bạn sẽ không phải khởi động lại Apache sau mỗi lần sửa đổi bạn thực hiện. –

+2

Tệp .htaccess đang ngày càng lớn và tôi nghe nói rằng máy chủ có thể đọc nó từ tệp vhosts hiệu quả hơn. Đúng không? – EricP

+2

Có, Apache có lẽ là _faster_ không có 'AllowOverride All' vì nó sẽ không phải đọc tệp .htaccess của bạn theo mọi yêu cầu. Tôi đoán đạt được hiệu suất là _very_ nhỏ ở đây. Những gì bạn hiện có trong '.htaccess' của bạn cho nó là lớn? –

Trả lời

11

này nên làm việc nếu bạn có mod_rewrite nạp.

<Directory /home/drupal_1> 
    Options FollowSymLinks Includes ExecCGI 
    AllowOverride All 
    DirectoryIndex index.html index.htm index.php 
</Directory> 
<Directory /home/movies> 
    Options FollowSymLinks Includes ExecCGI 
    AllowOverride All 
    DirectoryIndex index.html index.htm index.php 
</Directory> 
<VirtualHost 192.168.100.142:80> 
    ServerAdmin [email protected] 
    DocumentRoot /home/drupal_1 
    ServerName mysite.com 
    ServerAlias www.mysite.com 
    Alias /movies /home/movies/ 
    ErrorLog /var/log/httpd/mysite.com_err_log 
    CustomLog /var/log/httpd/mysite.com_log special 

    # Rewrite Rules ##################### 
    RewriteEngine On 
    RewriteRule ^/webmedia/(.*)/[R=301,L] 
    # end Rewrite Rules ################# 
</VirtualHost> 
+0

Cảm ơn bạn Seybsen. Điều đó là vậy đó. – EricP

+0

Tôi dễ dàng hơn trên máy chủ nếu có ít ghi đè trong các tập tin .htaccess và nhiều hơn nữa trong cấu hình vhost? Hay nó không quan trọng? – EricP

+1

Hãy xem câu trả lời này: http://stackoverflow.com/a/9555416/982002 – Seybsen