0

我正在使用 codeigniter,我尝试通过创建 .htaccess 文件及其内容从 url 中删除 index.php:

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

这种方式适用于 xampp 服务器。但是当我上传网站时,不幸的是出现了一个问题:

我有一个名为 files 的文件夹,它包含子文件夹:images、css、js、swf、upload。并且这些文件夹中的每个文件都无法查看,并且浏览器说那里找不到文件。

任何帮助请。

4

5 回答 5

2

只要确保你也排除那些:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|swf|upload)
RewriteRule ^(.*)$ /index.php/$1 [L]
于 2012-04-10T13:41:11.923 回答
2

这是我的 .htaccess 文件。我的理解是,对于任何尝试访问但不存在的文件或目录,它将转发到 Codeigniter。

任何确实存在的东西都可以正常工作,并且不需要单独排除。每次添加新目录或文件夹时,这将节省时间和麻烦,因为它不需要您编辑此文件。

RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

对我们有用,但我的理解可能不正确。希望能帮助到你

于 2012-04-10T14:17:20.493 回答
1

这是我的 .htaccess 文件 - 它应该适合你:

Options -Indexes
Options +FollowSymLinks

# Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>

    # activate URL rewriting
    RewriteEngine on

    # do not rewrite links to the documentation, assets and public files
    RewriteCond $1 !^(files|css|js|swfimages|assets|uploads|captcha)

    # do not rewrite for php files in the document root, robots.txt or the maintenance page
    RewriteCond $1 !^([^\..]+\.php|robots\.txt|crossdomain\.xml|maintenance\.html)

    # but rewrite everything else
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 index.php
</IfModule>  
于 2012-04-10T13:58:42.780 回答
1

试试这个我认为可以解决你的问题..

RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

您必须告诉您的服务器不要将这些目录处理到 index.php 并且为此工作的行是:

RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
于 2012-04-10T14:25:58.857 回答
1

谢谢你。这很好用:

RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

我有另一个网站和下一个 index.php 我有一个名为 files 的文件夹,这个文件夹包含很多内容,我应该将它们的所有名称和子目录的名称都放在其中吗?

于 2012-04-11T16:26:18.213 回答