【问题标题】:RewriteBase with WAMP not working (vhost)使用 WAMP 的 RewriteBase 不工作(虚拟主机)
【发布时间】:2014-12-19 09:24:10
【问题描述】:

我有一个问题,让我解释一下。

在 WAMP 上启用了 Rewrite_module

我的主机被映射:

127.0.0.1 localhost 
127.0.0.1 mydomain.com 

我的虚拟主机在 WAMP 上声明:

<VirtualHost *: 80>
  ServerAdmin contact@mydomain.com 
  DocumentRoot "E:/wamp/www/subfolder/" 
  ServerName mydomain.com
  ErrorLog "logs/mydomain.com.log" 
  CustomLog "logs/mydomain.com.log" common 
  <Directory "E:/wamp/www/subfolder /"> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow, deny 
    Allow from all
  </ Directory> 
</ VirtualHost>

现在,没问题,mydomain.com 到达 E:/wamp/www/subfolder/

我的项目位于子文件夹中,例如 E:/wamp/www/subfolder/my-project/

我有一个 htaccess:

<Mod_rewrite.c IfModule> 
RewriteEngine On 
RewriteBase /my-project/ 
RewriteRule ^index\php$ - [L] 
RewriteRule ^assets/css/(.*) /my-project/content/themes/assets/css/ $ 1 [QSA, L] [QSA, L] 
RewriteCond% {REQUEST_FILENAME}! F 
RewriteCond% {REQUEST_FILENAME}! -d 
RewriteRule. /my-project/index.php [L] 
</ IfModule> 

我的问题来了。如果我继续访问 mydomain.com/my-project/ 它没有问题,但没有加载 css(例如),因为链接是:

mydomain.com/content/themes/assets/css/ 它应该有:

mydomain.com/my-project/content/themes/assets/css/

我认为 RewriteBase 不工作,我不知道为什么。

非常感谢你,对不起我的英语。

【问题讨论】:

    标签: mod-rewrite rewrite wamp


    【解决方案1】:

    我认为您误解了虚拟主机的意义。

    您应该为每个项目创建一个虚拟主机,就像这样

    <VirtualHost *: 80>
      ServerAdmin contact@mydomain.com 
      DocumentRoot "E:/wamp/www/subfolder/project1" 
      ServerName mydomain1.com
      ErrorLog "logs/mydomain.com.log" 
      CustomLog "logs/mydomain.com.log" common 
      <Directory "E:/wamp/www/subfolder/project1"> 
        Options Indexes FollowSymLinks MultiViews 
        AllowOverride All 
        Order allow, deny 
        Allow from all
      </Directory> 
    </VirtualHost>
    
    <VirtualHost *: 80>
      ServerAdmin contact@mydomain.com 
      DocumentRoot "E:/wamp/www/subfolder/project2" 
      ServerName mydomain2.com
      ErrorLog "logs/mydomain.com.log" 
      CustomLog "logs/mydomain.com.log" common 
      <Directory "E:/wamp/www/subfolder/project2"> 
        Options Indexes FollowSymLinks MultiViews 
        AllowOverride All 
        Order allow, deny 
        Allow from all
      </Directory> 
    </VirtualHost>
    

    这使得每个项目看起来和反应都像是在其自己独特的 Apache 实例上的单个网站,并使您的项目移动到实时服务器更加可靠。

    您现在也不需要.htaccess,除非这个项目确实需要它。

    【讨论】:

    • 感谢您的回复,但我的问题就在这里。我必须保留 mydomain.com/my-project 格式,因为我必须使用具有 tree-mydomain.com/my 项目的外部数据库(位于服务器共享 dev 上)。再次感谢您。
    猜你喜欢
    • 2011-03-08
    • 2014-08-29
    • 2016-02-23
    • 2013-05-25
    • 2016-01-08
    • 2011-09-30
    • 1970-01-01
    • 2014-07-04
    相关资源
    最近更新 更多