我在使用 .htaccessmod_rewrite 要点的文件的驻留后的DocumentRoot.我的文件夹结构看起来是这样的:

home/
    webroot/
    other_files/

我有一个 .htaccess 文件在安装有以下内容:

RewriteEngine on
RewriteRule ^(.*)$ /home/other_files/$1

如果我试图访问 http://example.com/file.html 我收到以下错误:

所请求的URL/home/other_files/file.html 找不到对这种服务器。

它甚至有可能加载文件,这些文件后面的DocumentRoot?如果是这样,可以有人指给我正确的方向?

有帮助吗?

解决方案

我相信你需要添加一段

<Directory "/home/other_files">
  (options)
</Directory>

到服务器的结构之前阿帕奇将能够服务于任何从。例如,我DocumentRoot是/var/www但是这部分中的默认可的网站:

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

你可以再写一URL去/doc/和服务器就会知道哪里可以得到的文件。

其他提示

只是让你知道为什么这条规则不会的工作:

原因,它不能改写到 /home/other\_files/file.html 是mod_rewrite是分析路径 /home/webroot/home/other\_files/file.html 自从mod_rewrite的观点所述的削减是equivelant到你的文档根的 /home/webroot.

瑞恩*埃亨体育的建议 是一个体面之一,是有可能的路线,你要去的地方。

信贷转到Ryan Aheam,但我要拼出来。我是个初学者甚至与Ryan的答案我不得不尝试一些东西,获得法权利。

我想我DocumentRoot是我cake目录。但后来我不得不螳螂错误跟踪这只是常规php并因此不在的目录。本文件下面我下面的工作。

http://www.my_website.com :服务/var/www/cake

http://www.my_website.com/mantisbt :服务/var/www/html/mantisbt

文件/etc/httpd/conf/httpd.conf

Alias /mantisbt/ "/var/www/html/mantisbt/"                                                                          
<Directory "/var/www/html/">                                                                                        
    AllowOverride All                                                                                               
</Directory>                                                                                                        

<VirtualHost *:80>                                                                                                  
    ServerAdmin me@my_email.com                                                                             
    DocumentRoot /var/www/cakephp                                                                                   
    ServerName my_website.com                                                                                      
    <Directory /var/www/cakephp/>                                                                                   
        AllowOverride All                                                                                           
    </Directory>                                                                                                    
</VirtualHost>

文件/var/www/cake/.要

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^mantisbt/?$   /mantisbt/  [NC,L]
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top