【发布时间】:2013-10-23 05:43:03
【问题描述】:
我尝试了多种方法从我的 URL (http://www.example.com/index.php/login) 中删除 index.php,以及将 www 重定向到非 www 的 URL。
这是我的默认 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。
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: apache redirect ubuntu laravel-4 virtualhost