【问题标题】:Route to proper index.php with .htaccess使用 .htaccess 路由到正确的 index.php
【发布时间】:2014-03-17 23:01:24
【问题描述】:

我的 Codeigniter .htaccess 文件有问题...基本上是这样的。

常规 .htaccess 文件(适用于我的本地主机):

RewriteEngine On
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

我放置所有文件的网站文件夹结构:

website.com/
    css/
    js/
    img/
    index.html
    dev/
        application/
        assets/
        system/
        index.php
        .htaccess <<< A problem now exists with this file

当我转到website.com/dev/ 而不是 index.php 文件时,网站现在正在尝试加载index.html 文件。

我尝试了 .htaccess 文件的不同变体,但我得到了 500 服务器错误或 index.html 文件。

如何将website.com/dev/ 路由到正确的index.php 文件?

提前致谢! 文森特·威尔基


更新


我有一个部分工作的 .htaccess 文件:

RewriteEngine On
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ http://website.com/dev/index.php/$1 [L]

这只是部分工作,因为 URL 现在显示 .../dev/index.php/controller/method/args

我知道使用mod_rewrite 的全部意义在于从URL 中删除index.php ... :(

【问题讨论】:

    标签: php apache .htaccess codeigniter codeigniter-2


    【解决方案1】:

    你有那个目录结构是有原因的吗?因为不建议采用这种结构,这可能意味着您会遇到很多问题相反,您希望拥有一个类似的目录结构

    website.com/
        application/
        system/
        assets/
            css/
            js/
            img/
            index.php
            .htaccess
    

    您希望将您的applicationsystem 目录置于比您的Web 根目录(assets) 更高的级别,这样它们就不能被公开访问,这从安全角度来看要好得多。

    【讨论】:

    • 这个目录结构的原因是因为根目录(又名website.com/)已经被其他东西使用了。它还基于CodeIgniter PHP Framework,将.htaccessindex.php 放置在特定位置,我们所有的开发人员都在使用它。
    【解决方案2】:

    我有相同的目录结构。试试这个。

    .htaccess

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php/$1 [QSA,L]
    </IfModule>
    

    注意:我假设您使用的网站是 website.com/dev/

    希望这会有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-06
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多