【发布时间】:2013-08-14 10:19:43
【问题描述】:
[编辑]:How to remove "index.php" in codeigniter's path 的副本
[那里的解决方案不适合我]
我是第一次尝试 codeigniter,而且我对 php 还是很陌生。 我想从我的网址中删除 index.php。
安装的代码点火器
用我自己的替换 index.php
我的 .htaccess 中有这个
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#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>
我的重写是肯定的,我在我的根目录中加载了一个 phpinfo 页面,它显示了加载的模块。 我还检查了 httpd.conf
当我从 NetBeans 运行时,我被定向到 localhost:8888/domain/index.php 并加载我的索引页面
当我转到 localhost:8888/domain 时,我的 index.php 也会加载
当我转到 localhost:8888/domain/welcome 或 localhost:8888/domain/welcome.php 时,我得到 404 The requested URL /index.php/welcome was not found on this server.
当我转到 localhost:8888/domain/index.php/welcome 时,我被定向到欢迎控制器,但它只加载了我的 index.php,但没有标记。
我也在 .htaccess 中试过这个:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
我得到:
这也不起作用(我知道,他们都打算做几乎相同的事情):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,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>
我在 config/config.php 中有:
$config['base_url'] = 'localhost:8888/domain.com/';
$config['index_page'] = '';
【问题讨论】:
-
我猜
http:8888/domain/必须是http://domain:8888/在base_url但我不确定。 -
抱歉,这是一个 typeo,但它没有解决问题:现在是:$config['base_url'] = 'localhost:8888/domain.com/';
-
其实我刚刚注意到,去 domain/welcome 会给出错误信息:在此服务器上找不到请求的 URL /index.php/welcome。
-
为什么用自己的替换 index.php?您不必删除 index.php,您只需编辑默认控制器名称和路由路径。
-
是的,我也注意到了。但是这些 .htaccess 黑客并没有将 domain/index.php/welcome 或 domain/index.php/welcome.php 发送到 domain/welcome 这应该是正确的吗?哦好的。所以他们只会使用我想的路线吗?
标签: php .htaccess codeigniter mod-rewrite