使用.htaccess路由到适当的index.php
我的Codeigniter使用.htaccess路由到适当的index.php,php,apache,.htaccess,codeigniter,codeigniter-2,Php,Apache,.htaccess,Codeigniter,Codeigniter 2,我的Codeigniter.htaccess文件有问题。。。基本上是这样的 常规.htaccess文件(适用于我的本地主机): 我放置所有文件的网站文件夹结构: website.com/ css/ js/ img/ index.html dev/ application/ assets/ system/ index.php .htaccess <<< A pr
.htaccess
文件有问题。。。基本上是这样的
常规.htaccess文件(适用于我的本地主机):
我放置所有文件的网站文件夹结构:
website.com/
css/
js/
img/
index.html
dev/
application/
assets/
system/
index.php
.htaccess <<< A problem now exists with this file
这只是部分起作用,因为URL现在显示为../dev/index.php/controller/method/args
我知道使用
mod_rewrite
的全部目的是从URL中删除index.php
:(有这样的目录结构的原因吗?因为不建议采用这种结构,这可能意味着您会遇到很多问题,相反,您希望有这样的目录结构
website.com/
application/
system/
assets/
css/
js/
img/
index.php
.htaccess
您希望将
应用程序
和系统
目录放置在比您的web根目录(资产
)更高的级别,以便它们不可公开访问,这从安全角度看要好得多。我有相同的目录结构。请尝试此操作
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
重新启动发动机
重写cond%{REQUEST_FILENAME}!-d
重写cond%{REQUEST_FILENAME}!-f
重写规则^(.*)$index.php/$1[QSA,L]
注意:我假设您使用的网站是website.com/dev/
希望这对您有所帮助:)此目录结构的原因是根目录(aka
website.com/
)已用于其他用途。它还基于CodeIgniter PHP框架
,该框架将.htaccess
和index.PHP
放置在特定位置,是我们所有开发人员使用的。
website.com/
application/
system/
assets/
css/
js/
img/
index.php
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>