.htaccess mod_rewrite在子目录中不起作用 [英] .htaccess mod_rewrite not working in subdirectory

查看:99
本文介绍了.htaccess mod_rewrite在子目录中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用htaccess将所有请求重写到我域中子文件夹中的main.php.我的.htaccess中的代码如下:

I am trying to use htaccess to rewrite all requests to main.php in a subfolder on my domain. The code in my .htaccess is the following:

RewriteEngine on
RewriteBase /public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . main.php [L]

我确定模块已启用,已经使用apache2ctl -M命令进行了检查

I am sure the module is enabled, I have checked using the apache2ctl -M command

root@vps847:/etc/apache2/sites-available# apache2ctl -M
Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 alias_module (shared)
 auth_basic_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 php5_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 ssl_module (shared)
 status_module (shared)
Syntax OK

在我的默认站点中,我添加/编辑了以下几行:

In my default site I have added/edited the following lines:

<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>
<Directory /var/www/public>
        AllowOverride All
</Directory>

在每次编辑内容后,我都会重新启动apache.但是,每次浏览公共目录时,我都会看到apache目录列表.我已经尝试过将.htaccess添加到我的apache的根目录,但是它也不起作用.当我向.htaccess文件中添加错误时,我确实会收到内部服务器错误.

I have restarted apache every time after editing something. Yet, everty time I surf to the public directory I see the apache directory listing. I have already tried to add a .htaccess to the root of my apache, but it didn't work either. When I add an error to my .htaccess file I do get an internal server error though.

有人可以发现我的配置出了什么问题吗?我正在使用Ubuntu服务器12.04.

Can someone find what is wrong with my configuration? I am using Ubuntu server 12.04.

推荐答案

将此内容包含在/public/.htaccess中:

DirectoryIndex main.php

RewriteEngine on
RewriteBase /public/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . main.php [L]

这篇关于.htaccess mod_rewrite在子目录中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆