我一直试图让我的.htaccess
文件在我的本地主机上工作。我知道该文件可以工作,因为它在我的服务器上并且可以工作。但是,它似乎不在本地运行。
我已按照我可以找到的设置所有内容的教程进行操作,以下是我的/etc/apache2/sites-available/default
文件开头:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
这是我的蚕食站点位于同一目录中的代码:
<VirtualHost *:80>
ServerName nibble.local
DocumentRoot /var/www/nibble_framework/web/
<Directory /var/www/nibble_framework/web/>
AllowOverride All
Options Indexes FollowSymLinks MultiViews
Allow from All
</Directory>
RewriteLog /var/www/rewrite.log
ErrorLog /var/log/apache2/error.log
</VirtualHost>
我已经使用a2ensite启用了该站点并重新启动了apache。我还将该站点添加到了我的主机文件中:
127.0.0.1 nibble.local
我已经使用a2enmod启用了mod rewrite,并多次重启/重新加载了Apache。
$ a2enmod rewrite
Module rewrite already enabled
我的.htaccess
文件在其中,/var/www/nibble_framework/web/.htaccess
并具有以下代码:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?.*$ - [E=FILE:%{DOCUMENT_ROOT}/$1.php]
RewriteCond %{ENV:FILE} !^$
RewriteCond %{ENV:FILE} -f
RewriteRule ^([^/]*)/?(.*)$ $1.php?url=$2 [QSA,L]
RewriteCond %{ENV:FILE} !^$
RewriteCond %{ENV:FILE} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
当我执行时print_r($_REQUEST)
,即使url由一个长字符串填充,它也始终是一个空数组。
有谁知道为什么这可能会失败?
编辑:
apache2访问日志:
~$ tail -f /var/log/apache2/access.log
::1 - - [16/Aug/2011:07:32:39 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:39 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:39 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
我怀疑您的VirtualHost没有得到正确处理,因此不会为get请求设置AllowOverride。首先,您的/etc/hosts
文件应如下所示。
127.0.0.1 localhost localhost.localdomain
127.0.1.1 nibble.local
其次,您必须为基于名称的虚拟主机设置该接口。您尚未指定当前是否已设置。通常,它是在主apache配置中设置的,我猜ubuntu / debian的文件位于/etc/apache2/apache2.conf
。确保此行设置在该文件中的某个位置,
NameVirtualHost *:80
完成这些更改后,请重新启动apache
sudo /etc/init.d/apache2 restart
否进行测试,请记住您仅将主机条目设置为本地。因此,只有当本地主机发出请求时,它才能正常工作。如果您被卡住或无法使用,请从中发布相关行/var/log/apache2/error.log
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句