This is one of the most repeated questions, but I did not get it and had to ask. I use CI 2. I removed index.php from URL by following steps:
这是最重复的问题之一,但我没有得到,不得不问。我使用CI 2。我删除索引。php从URL通过以下步骤:
- In
config.php
I set - 在配置。php我设置
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
- In
routes.php
I set - 在路线。php我设置
$route['default_controller'] = "InterviewController";
- here is my .htaccess
- 这是我的。htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|img|robots\.txt|css|js|libraries/ckeditor|upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
addDefaultCharset UTF-8
- I enabled
mod_rewrite
on the web server. - 我在web服务器上启用了mod_rewrite。
So in the index()
method of InterviewController
, I load the addInterview.php
view. After that, it is being called addInterview
as the default page of the site when I type just the domain name. Problem occurs when I press Save button on addInterview
page which must call saveInterview()
from InterviewController
. But in this step I get The requested URL was not found on this server (404) error
. saveInterview()
even hasn't been called. But if I myself type domainname/index.php/InterviewController/saveInterview everything works. Seems like I removed index.php
just from default page, but not from all pages of my site. What do you recommend?
所以在InterviewController的index()方法中,我加载了addInterview。php视图。之后,当我输入域名时,它被称为addInterview作为网站的默认页面。当我在addInterview页面上按下Save按钮时,就会出现问题,该按钮必须从InterviewController调用saveInterview()。但是在这个步骤中,我获得了请求的URL在这个服务器(404)错误中没有找到。saveInterview()甚至还没有被调用。但是如果我自己输入domainname/index。php / InterviewController / saveInterview一切正常。好像我删除了索引。php只是从默认页面,但不是从我的站点的所有页面。你推荐什么?
4 个解决方案
#1
3
The leading slash could be causing your problem.
领先的斜线可能会导致你的问题。
Change
改变
RewriteRule ^(.*)$ /index.php/$1 [L]
to
来
RewriteRule ^(.*)$ index.php [L]
#2
1
try this...its Working for me
试试这个…它为我工作
RewriteEngine on
RewriteBase /Ur_Folder_Path/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Ur_Folder_Path/index.php?/$1 [L]
#3
1
edite your .htaccess file to>
编辑您的.htaccess文件到>。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>
#4
0
Change the rewrite rule to
将重写规则更改为。
RewriteRule ^(.*)$ /YOUR_CI_PROJECT_NAME/index.php/$1 [L]
#1
3
The leading slash could be causing your problem.
领先的斜线可能会导致你的问题。
Change
改变
RewriteRule ^(.*)$ /index.php/$1 [L]
to
来
RewriteRule ^(.*)$ index.php [L]
#2
1
try this...its Working for me
试试这个…它为我工作
RewriteEngine on
RewriteBase /Ur_Folder_Path/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Ur_Folder_Path/index.php?/$1 [L]
#3
1
edite your .htaccess file to>
编辑您的.htaccess文件到>。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>
#4
0
Change the rewrite rule to
将重写规则更改为。
RewriteRule ^(.*)$ /YOUR_CI_PROJECT_NAME/index.php/$1 [L]