允许覆盖虚拟主机中的路径

时间:2019-08-17 02:01:58

标签: apache .htaccess

外部驱动器上有一些PHP文件,这些文件映射到Windows 10计算机上的Z:驱动器。这段代码位于httpd-vhosts.conf Apache文件中:

<VirtualHost *:8080>    
    DocumentRoot "Z:/files/xampp/htdocs"
    <Directory "Z:/files/xampp/htdocs">
        Options Indexes
        Require all granted
    </Directory>
</VirtualHost>

当前的任务是允许.htaccess覆盖上面显示的路径内的文件路径。在httpd.conf文件中,重写模块已启用。该行如下所示:LoadModule rewrite_module modules/mod_rewrite.so。我尝试将这段代码添加到httpd.conf文件中:

<Directory "Z:/files/xampp/htdocs/miscellaneous/WebServiceExamples">
    AllowOverride All
</Directory>

进行这些更改后,Apache Web服务器已停止并重新启动。 .htaccess中的代码如下:

<IfModule mod_rewrite.c>

# turn rewrite engine on
Options +FollowSymlinks
RewriteEngine on

# map neat URL to internal URL
RewriteRule ^mobile/list/$   RestController.php?view=all [nc,qsa]
RewriteRule ^mobile/show/([0-9]+)/$   RestController.php?view=single&id=$1 [nc,qsa]

</IfModule>

但是,当在Chrome地址栏中输入.htaccess文件中的重写规则应处理的URL时,结果是找不到对象!错误404 。我在哪里迷路了?

编辑:
我尝试过的另一件事是将httpd.conf恢复到原始状态,然后按如下所示修改httpd-vhosts.conf

<VirtualHost *:8080>    
    DocumentRoot "Z:/files/xampp/htdocs"
    <Directory "Z:/files/xampp/htdocs">
        Options Indexes
        Require all granted
    </Directory>
    <Directory "Z:/files/xampp/htdocs/miscellaneous/WebServiceExamples">
        AllowOverride All
    </Directory>
</VirtualHost>

在停止并重新启动Apache Web服务器之后,结果仍然与以前相同: 找不到对象!错误404。

1 个答案:

答案 0 :(得分:0)

弄清楚了。配置文件处于原始帖子中“编辑”部分所述的状态。 this link中的“疑难解答”部分对确定配置文件是否正确设置很有帮助。

这是在Chrome地址栏中输入的网址:http://localhost:8080/miscellaneous/WebServiceExamples/SimpleRestfulWebService/mobile/list。请注意,没有尾随的正斜杠。重写规则在.htaccess中的编写方式使强制斜杠成为必需。当修改了重写规则行以使尾斜杠为可选时,则可以正常工作。这是修改后的重写规则:

RewriteRule ^mobile/list/?$   RestController.php?view=all [nc,qsa]
RewriteRule ^mobile/show/([0-9]+)/?$   RestController.php?view=single&id=$1 [nc,qsa]