Ubuntu Server 12.04 Apache httpd 2.2.22 mod_rewrite 不起作用

Ubuntu Server 12.04 Apache httpd 2.2.22 mod_rewrite 不起作用

我正在尝试使用 apache2 设置分布式 Web 场。在将配置部署到我的其他 3 台服务器之前,我想让一切在 10.0.2.1 上的第一台服务器(指定为 P-WEB-01)上正常工作。我通过虚拟主机设置了多个站点,不同的域名都正常工作。

但是,我的问题出在 apache_mod_rewrite,我试图设置一个如下所示的 URL:http://example.com/firstvariable/secondvariable/thirdvaraible并让 PHP 脚本 (index.php) 读取它http://example.com/index.pp?a=firstvariable&b=secondvariable&c=thirdvariable。系统还必须以某种方式进行设置,使 mod_rewrite 忽略内部文件名和目录,因为它们通过脚本代理到外部站点(出于安全目的)。

我在 IIS7 服务器上运行了此脚本一段时间,它运行得非常好。此外,我遵循了整个 a2enmod mod_rewrite,它输出成功。我在 apache2.conf 中启用了 AllowOverride All,并在站点的根目录中设置了站点 .htaccess 文件,并让它显示:

RewriteEngine on
RewriteRule ^index.php$ index.html

但仍然没有起到任何作用。

答案1

我用了

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([\w.]+)/?$ index.php?a=$1 [L,QSA]
RewriteRule ^(\w+)/([\w.]+)/?$ index.php?a=$1&b=$2 [L,QSA]
RewriteRule ^(\w+)/(\w+)/([\w.]+)/?$ index.php?a=$1&b=$2&c=$3 [L,QSA]

并确保我的防火墙(基于 IPTables)实际上转发到正确的(新)网络服务器。

感谢大家! :)

相关内容