example.com
我在 Ubuntu 12.04 上使用 Apache 2.2.22 和 PHP 5.3.10。为了回答这个问题,真实的域名已经被混淆了。
我正在尝试设置AllowOverride
为。我的 中None
目前有一个文件。它看起来像这样:.htaccess
DocumentRoot
<IfModule mod_rewrite.c>
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# deal with php5-cgi first
<IfModule mod_fcgid.c>
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
<IfModule !mod_fcgid.c>
# for normal Apache installations
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# for Apache FGCI installations
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
</IfModule>
</IfModule>
我运行后phpinfo()
发现我的Server API
是Apache 2.0 Handler
。这让我想到我需要的重写规则是RewriteRule ^(.*)$ index.php/$1 [L]
。对吗?
我尝试将此重写规则移到我的sites-available/example.com
配置文件中,但每当我设置AllowOverride
为时None
,都会出现 500 错误。
这是我example.com
之前的配置文件:
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster@localhost
DocumentRoot /httpd/www/example.com/public
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /httpd/www/example.com/public>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/example.com-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/example.com-access.log combined
</VirtualHost>
上述配置工作正常。我尝试将.htaccess
文件的内容合并到我的sites-available/example.com
文件中。结果如下:
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster@localhost
DocumentRoot /httpd/www/example.com/public
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /httpd/www/example.com/public>
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/example.com-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/example.com-access.log combined
</VirtualHost>
哇哦。真是个菜鸟。你知道我做错了什么吗?我当然知道。
答案1
也许如果我把RewriteCond
和RewriteRule
指令按正确的顺序RewriteCond
排列(前 RewriteRule
)...是的,这有帮助。