[英]Can we use CodeIgniter without htaccess file
我是CodeIgniter的初学者,并且遇到我的.htaccess
文件问题。 .htaccess
文件是否需要与CodeIgniter一起使用?
是的,可以,但是如果您不使用特殊的Web服务器(如nginx
,则无法从URL删除index.php
。
如果您不.htaccess
在Apache Web服务器上使用.htaccess
文件,则您的URL如下所示(实际上您可以通过httpd.conf
删除它,但不建议这样做):
http://www.yourdomain.com/index.php/your-url
如果您更喜欢使用nginx,则应按以下方式编辑nginx.conf
文件:
server {
server_name domain.tld;
root /your/codeigniter/folder;
index index.html index.php;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
}
您应该在nginx.conf
html {}
标签之间添加此片段
如果您更喜欢Apache + .htaccess,并且想要删除index.php
,则应该创建一个.htaccess
文件,如下所示:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
请查看Codeigniter URL指南以获取所有详细信息。 我也同意@ geggleto,.htaccess文件不仅用于index.php,还可以使用htaccess做很多事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.