我正在尝试使用htaccess重写我域上的子文件夹中对main.php的所有请求。我的.htaccess中的代码如下:
RewriteEngine on
RewriteBase /public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . main.php [L]
我确定模块已启用,我已使用apache2ctl -M
命令
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
在我的默认网站中,我添加/编辑了以下行:
<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文件添加错误时,我确实收到了内部服务器错误。
有人可以找到我的配置有什么问题吗?我正在使用Ubuntu服务器12.04。
答案 0 :(得分:4)
在/public/.htaccess
:
DirectoryIndex main.php
RewriteEngine on
RewriteBase /public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . main.php [L]
答案 1 :(得分:2)
我遇到了这个问题,并找到了可行的解决方案:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /tools/admin
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /tools/admin/index.php [L]
希望这有助于某人