我已经尝试了几种方法来删除index.php从我的网址(http://www.example.com/index.php/login),以及重定向www到非www网址.
以下是我的默认Apache VirtualHost文件:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/public/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
字符串
现在我在这个文件中添加了以下内容:
Redirect 301 / http://example.com
型
但这并没有工作,我只是得到一个重定向循环消息。我也有以下.htaccess:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
型
对此我补充道:
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
型
但这也行不通。
另一个问题是,对于我的所有路由,我必须包括index.php,如http://example.com/index.php/test
就好像我的.htaccess文件被忽略了。
服务器是运行Ubuntu 13.04 x64的DigitalOcean Droplet。PHP 5.4.9和Apache 2.2.22。
如有任何帮助,我们将不胜感激。- 谢谢-谢谢
1条答案
按热度按时间kgsdhlau1#
mod_rewrite
未在我的服务器上启用。通常这是默认情况下,在所有的服务器,我曾经用过,所以它没有点击,因为我从来没有启用它,但在这个DigitalOcean服务器,它不是。我使用
a2enmod rewrite
来启用它,然后重新启动Apache。