duangu6431 2013-09-17 00:45
浏览 64
已采纳

htaccess在虚拟主机中不起作用,但在默认站点中是

Im having some issues with the virtual hosts apache files and htaccess. I have apache, updated to 2.6 yesterday. I installed 2 virtual domains on it, and disabled the default domain. All works fine, sites loads fine, no problems there.

The first virtual domain has a htaccess with +50 rewrite conditions and all them work fine! I tried to add some conditions to the 2nd domain, but the ones that rewrite directories dont work.

This is the condition:

RewriteRule ^user/([a-zA-Z0-9_-]+)$ index.php?username=$1
RewriteRule ^user/([a-zA-Z0-9_-]+)/$ index.php?username=$1

And there, the "sites-available" apache config files for each domain (only the relevant things):

DOMAIN 1:

ServerAdmin webmaster@localhost
    ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /var/www/domain1.com/public_html
<Directory />
    Options FollowSymLinks
    AllowOverride ALL
</Directory>
<Directory /var/www/domain1.com/public_html/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride ALL
    Order allow,deny
    allow from all
</Directory>

DOMAIN2:

ServerAdmin webmaster@localhost
    ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /var/www/domain2.com/public_html
<Directory />
    Options FollowSymLinks
    AllowOverride ALL
</Directory>
<Directory /var/www/domain2.com/public_html/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride ALL
    Order allow,deny
    allow from all
</Directory>

As you can see, there is no diference between them other than the path to main folder. I dont understand whats wrong with it. Why the first domain works perfect and the second one no.

Some things:

A: Any other condition on the domain2 htaccess file works just fine, like redirec simply html to php, or errorhandlers, or just simply redirects to test.

B: I pasted the same rewrite condition in my first domain htaccess file, and it works perfect!

It looks like the apache config file is not working correctly.

Is there anything I must check/change?

I will appreciate any help, and sorry for my english.

  • 写回答

1条回答 默认 最新

  • dowjgrm6787 2013-09-17 02:14
    关注

    Give this a try its tested and working:

    Options +FollowSymLinks -MultiViews 
    
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^user/([a-z0-9_-]+)/?$ /index.php?username=$1 [NC,L]
    

    I believe the issue is that you have MultiViews enabled, you can also resume your 2 rules into 1 like I have done above.

    This should go into the .htaccess of your domain2.

    As a side note, you do not need 2 directories directives, you can remove this one:

    <Directory />
        Options FollowSymLinks
        AllowOverride ALL
    </Directory>
    

    And keep just:

    <Directory "/var/www/domain2.com/public_html">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride ALL
        Order allow,deny
        allow from all
    </Directory>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架