【问题标题】:.htaccess to vhost.ht 访问虚拟主机
【发布时间】:2011-05-20 16:09:07
【问题描述】:

任何人都知道要在 vhost.conf 中放入什么以供 apache 复制(来自 .htaccess):

RewriteEngine on  
RewriteCond $1 !^(index\.php|images|scripts|css|uploads|robots\.txt)  
RewriteRule ^(.*)$ /index.php/$1 [L]  

基本上,我希望除 /images、/scripts 或 /css 之外的所有请求都通过 /index.php。

当我使用 .htaccess 文件时它可以工作,但我也想知道如何通过 vhost.conf 来做。任何人都知道在性能、稳定性等方面是否也使用一个比另一个更好(vhost.conf vs htaccess)?

【问题讨论】:

  • 您应该能够将 1:1 放入 VirtualHost 指令中

标签: apache .htaccess mod-rewrite virtualhost


【解决方案1】:

在模式前添加/ 时应该可以工作:

RewriteCond $1 !^(index\.php|images|scripts|css|uploads|robots\.txt)
RewriteRule ^/(.*)$ /index.php/$1 [L]

或者:

RewriteCond $1 !^/(index\.php|images|scripts|css|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

.htaccess 文件的缺点是它们实际上需要在每个请求中解释,而虚拟主机配置只在服务器启动时解释一次。

【讨论】:

    【解决方案2】:

    秋葵++

    我在 httpd wiki 上写了这篇文章来解决类似这样的问题。

    http://wiki.apache.org/httpd/RewriteContext

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-17
      • 2020-07-17
      • 1970-01-01
      • 2012-12-28
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多