专家。我正在使用codeigniter。我使用.htaccess从我的url中删除'index.php',并将“Allow from all”添加到我的default.conf中。 'index.php'已成功删除,网站正在运行。但是自上次更新apache以来,.htacess停止了工作,并且在URL中需要'index.php'。这是我新更新的000-default.conf。
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
#vim: syntax=apache ts=4 sw=4 sts=4 sr noet
我在000-default.conf中添加了以下行,但没有用:
AllowOverride all
Order allow,deny
Allow from all
我的.htaccess没问题,因为它在上次更新Apache之前工作正常。
Options -Indexes
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{REQUEST_URI} ^htaccess/ [NC,OR]
RewriteCond %{REQUEST_URI} ^system/function/ [NC,OR]
#just make sure the last rule does NOT have an OR
RewriteCond %{REQUEST_URI} ^system/class/ [NC]
RewriteRule . - [R=404,L,NC]
我的apache版本是2.4.6。现在请告诉我要添加到000-default.conf以使.htaccess工作并从我的网站url中删除'index.php'。
P.S:我正在使用ubuntu 12.04。 mod_rewrite已启用。我启用了000-default.conf,即它在我的启用站点的文件夹中可用。
答案 0 :(得分:8)
我仍然是服务器/命令行的新手,所以我想我会在类似的地方为其他人添加一步一步的解决方案。希望这有助于某人:
登录您的服务器。
使用nano:
打开000-default.config文件$ sudo nano /etc/apache2/sites-available/000-default.conf
在VirtualHost中查找此行:DocumentRoot /var/www/html
并在其下方添加以下内容:
<Directory /var/www >
AllowOverride All
</Directory>
保存您的修改: 按 CTRL + O 进行写入;然后按 RETURN 保存更改
退出Nano: 按 CTRL + X
重启服务器:
$ sudo service apache2 restart
如果需要激活apache mod_rewrite模块,请运行以下命令:
$ sudo a2enmod rewrite
如果模块已经激活,您将收到一条消息,告诉您一切顺利。
答案 1 :(得分:7)
这有点旧了,但是因为我现在看到它并且我得到它的工作,也许这将澄清任何绊倒它的人。
你打开那个000-default.conf文件并找到它所在的位置“/ var / www”然后将其放入:
<Directory /var/www>
AllowOverride All
</Directory>
然后只需保存并重新启动apache即可。您还需要为Apache启用mod_rewrite。 Googling很容易找到。
答案 2 :(得分:1)
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory /var/www >
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
)