Cod*_*ict 7 ubuntu .htaccess codeigniter apache2
伙计们.我正在使用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
Run Code Online (Sandbox Code Playgroud)
我在000-default.conf中添加了以下行,但是没有用:
AllowOverride all
Order allow,deny
Allow from all
Run Code Online (Sandbox Code Playgroud)
我的.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]
Run Code Online (Sandbox Code Playgroud)
我的apache版本是2.4.6.现在请告诉我要添加到000-default.conf以使.htaccess正常工作并从我的网站url中删除'index.php'.
PS:我使用的是ubuntu 12.04.mod_rewrite已启用.我启用了000-default.conf,即它在我的启用站点的文件夹中可用.
小智 8
我仍然是服务器/命令行的新手,所以我想我会在类似的地方为其他人添加一步一步的解决方案.希望这有助于某人:
登录您的服务器.
使用nano打开000-default.config文件:
$ sudo nano /etc/apache2/sites-available/000-default.conf
Run Code Online (Sandbox Code Playgroud)在VirtualHost中查找此行:DocumentRoot /var/www/html
并在其下方添加以下内容:
<Directory /var/www >
AllowOverride All
</Directory>
Run Code Online (Sandbox Code Playgroud)保存编辑:按CTRL + O进行写入; 然后按RETURN保存更改
退出Nano:按CTRL + X.
重启你的服务器:
$ sudo service apache2 restart
Run Code Online (Sandbox Code Playgroud)如果需要激活apache mod_rewrite模块,请运行以下命令:
$ sudo a2enmod rewrite
Run Code Online (Sandbox Code Playgroud)
如果模块已经激活,您将收到一条消息,告诉您一切顺利.
小智 7
这有点旧了,但是因为我现在正在看它并且我得到了它的工作,也许这将为任何绊倒它的人澄清.
你打开那个000-default.conf文件并找到它所在的位置"/ var/www"然后将其放入:
<Directory /var/www>
AllowOverride All
</Directory>
Run Code Online (Sandbox Code Playgroud)
然后只需保存并重启apache即可.您还需要为Apache启用mod_rewrite.Googling很容易找到.
归档时间: |
|
查看次数: |
8112 次 |
最近记录: |