0

我正在使用雪豹,我有我的本地环境,我正试图摆脱 url 中的 index.php ......这就是我所拥有的

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

我的配置文件有这个

$config['index_page'] = "";

但是当我访问没有 index.php 的页面时它不起作用

这行得通

http://localhost/ci_example/index.php/site

这不是

http://localhost/ci_example/site

我试图遵循这个

也许我需要对我的本地 conf 文件做一些事情......但我真的不知道是什么,我不知道如何重新启动 apache 命令行......任何想法

4

5 回答 5

4

当您说“它不起作用”时,您是什么意思?你有错误吗?白屏?500 错误?

您是否确保您的 httpd.conf 文件已将AllowOverride设置设置为All?如果没有,它可能没有使用您的 .htaccess 文件,这意味着不会使用重写规则。

于 2010-12-23T01:25:10.190 回答
1

试试这个 .htaccess 代码并更改基本路径,它将适用于所有 Godaddy 和其他主机。


选项

选项 - 多视图选项 +FollowSymLinks

启用模组重写

重写引擎开启

您网站的根目录的位置

如果为子目录写,你会输入 /subdirectory

RewriteBase /winscore

删除用户对 CodeIgniter 系统文件夹的访问。

此外,这将允许您创建一个 System.php 控制器,

以前这是不可能的。

如果您已重命名系统文件夹,则可以替换“系统”。

RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/$1 [L]

检查用户是否正在尝试访问有效文件,

例如图像或 css 文档,如果不是这样,它会发送

请求 index.php

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d

最后一个条件允许访问图像和 css

文件夹和 robots.txt 文件

RewriteCond $1 !^(index.php|images|robots.txt|css)

RewriteRule ^(.*)$ index.php?/$1 [L]


于 2011-01-06T11:49:02.813 回答
0

尝试在 .htaccess 文件中添加 RewriteBase

RewriteEngine On
RewriteBase /ci_example
于 2010-12-23T02:03:53.983 回答
0

这是在 OS X 上对我有用的东西。

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

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

以上内容无需任何修改即可为您工作。如果您托管在一个文件夹中,可以说像http://myserver.com/my_app/然后在两个地方都将/index.php更改为/my_app/index.php

请务必进入 config.php 并将url_protocol更改为PATH_INFO

于 2010-12-23T19:18:24.847 回答
0

将其复制到您的 .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /CI_FOLDER/
#CI_FOLDER is the Location of your CI files.

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
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.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>  
于 2013-08-25T10:55:57.637 回答