【问题标题】:.htaccess file not found.htaccess 文件未找到
【发布时间】:2014-04-11 22:11:15
【问题描述】:

我的网站由我的朋友完成,它已在公共服务器上启动并运行。我试图在我的内部服务器上运行相同的网站。但是apache说找不到文件。我发现问题出在 .htaccess 文件中。这是我的文件

AddType text/x-component .htc
#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

在我的 apache conf 文件中我设置了

<VirtualHost *:80>

DocumentRoot /srv/www/
    <Directory />
            Options FollowSymLinks
            AllowOverride All
    </Directory>

    <Directory /srv/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order Deny,Allow
            Deny from all
            Allow from 192.168.43.0/255.255.255.0 192.168.42.0/255.255.255.0
<Directory /srv/www/companies/test1/>
            Options +Indexes +FollowSymLinks +MultiViews
            AllowOverride All
            Order Allow,Deny
            Deny from all
            Allow from 192.168.43.0/255.255.255.0 192.168.42.0/255.255.255.0
    </Directory>
    </Virtualhost>

错误日志显示

[Fri Apr 11 16:57:33 2014] [error] [client 192.168.43.8] File does not exist:/srv/www/cms
[Fri Apr 11 16:57:33 2014] [error] [client 192.168.43.19] File does not exist:/srv/www/products, referer: http://192.168.43.8/companies/

我猜 htaccess 在 /srv/www/ 文件夹而不是 /srv/www/companies/test1/ 文件夹中寻找 index.php。有什么建议如何将 htaccess 引导到正确的位置?

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    假设您在 /srv/www/companies/test1/ 而不是 /src/www/ 中有 cms 和产品目录,您可以通过将 DocumentRoot /srv/www/ 更改为 DocumentRoot /srv/www/companies/test1/ 并重新启动 apache 来解决此问题。

    不过,通常情况下,您希望为您计划服务的每个站点设置一个自定义虚拟主机,并将默认的 &lt;VirtualHost *:80&gt; 设置为访问您的 IP 地址时默认应提供的任何内容。

    有关常见设置的一些示例,请参阅 VirtualHost Examples

    【讨论】:

    • 感谢您的洞察力。但我无法更改我的 DocumentRoot,因为还有其他服务正在运行。也许我可以为这个网站使用其他端口?
    • 我建议您实现我在回答的第二部分中提到的内容,并设置一个新的 VirtualHost,并将 DocumentRoot 设置为正确的路径。您可以使用另一个端口或使用相同的端口,但切换到使用 Host: 标头的“命名虚拟主机”来确定应该为哪个站点提供服务。我的“VirtualHost Examples”链接中提供了每个场景的示例。
    【解决方案2】:

    .htaccess 文件位于安装的根文件夹中,默认情况下是隐藏的。

    如果您使用的是 FileZilla:

    1. 启动 FileZilla,然后选择顶部的“服务器”菜单
    2. 选择“强制显示隐藏文件”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-04
      • 2016-12-08
      • 2016-05-17
      • 1970-01-01
      相关资源
      最近更新 更多