[英]Codeigniter remove /index.php from URL
Okay so I know that a lot of people have been asking the same or similar questions, but I don't seem to find a solution that works for my project. 好的,所以我知道很多人都在问相同或类似的问题,但是我似乎找不到适合我项目的解决方案。 So please don't put this as a duplicate.
因此,请勿将其重复。
I have a website made with codeigniter. 我有一个使用codeigniter创建的网站。 It was running just fine without the index.php in the url.
在URL中没有index.php的情况下,它运行得很好。 So the rewrite was successfull.
因此重写成功。 Until a few days ago: all of a sudden the admin area (/admin) returned a 404 and was only accessible by the path '/index.php/admin'.
直到几天前:突然,管理区域(/ admin)返回了404,并且只能通过路径'/index.php/admin'访问。 The rewrite code that once used to work didn't do a thing anymore.
曾经起作用的重写代码不再起作用。
And know I'm back at the start -> the problem is that I cannot delete the index.php from my url. 并且知道我回到了开头-> 问题是我无法从我的网址中删除index.php。
I tried so many things that I don't know what to do anymore. 我尝试了很多事情,以至于我不知道该怎么办。
The application is stored under 'public_html/application/... The image below is inside the application folder where the .htaccess file and index.php are. 该应用程序存储在“ public_html / application / ...”下。下图位于.htaccess文件和index.php所在的应用程序文件夹中。 Is this the right location to change the .htaccess?
这是更改.htaccess的正确位置吗?
I tried rewriting the .htaccess but without success: 我尝试重写.htaccess,但未成功:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^CI/(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots|css\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
My config file: 我的配置文件:
$config['base_url'] = 'http://www.mysite.be/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Routes.php: routes.php文件:
$route['default_controller'] = "c_home/index";
$route['404_override'] = '';
$route['admin'] = "c_home/adminpanel";
$route['logout'] = "c_login/logout";
Does anybody have a clue what is going on or how this can be fixed? 是否有人知道发生了什么或如何解决?
Thanks in advance! 提前致谢!
The .htaccess should be in the public_html directory -- ie: one level up from the current location. .htaccess应该位于public_html目录中-即:从当前位置上一层。 The index.php is presumably in public_html already and The index.* you have in the picture is index.html -- as it should be.
index.php大概已经在public_html中了,图片中的index。*应该是index.html-应该是这样。 If .htaccess is in the right place per the above, then this .htaccess code will work:
如果.htaccess在上述各项中的正确位置,则此.htaccess代码将起作用:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
So I have been messing around with this and finally made it work 所以我一直在弄弄这个,最后使它起作用
For this I made changes to the htaccess and controllers. 为此,我对htaccess和控制器进行了更改。
I changed the admin function to a new controller and changed this in the routes.php 我将管理功能更改为新的控制器,并在routes.php中进行了更改
new routing 新路线
$route['admin'] = "c_login/index";
new .htaccess 新的.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Try set 尝试设置
$config['uri_protocol'] = 'PATH_INFO'
And set 并设置
$config['enable_query_strings'] = FALSE;
If we need a remove /index.php from url in codeigniter Than 如果我们需要从codeigniter中的URL中删除/index.php,请选择
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
RewriteEngine on
RewriteBase /[Your project folder name]/
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Now you can access like 现在您可以像访问
http://example.com/controller/method http://example.com/controller/method
May it's helpfull for you 可能对您有帮助
I don't know what the heck you're doing with all that code, but I just put this in my .htaccess file: 我不知道您对所有这些代码的处理方式,但是我只是将其放在我的.htaccess文件中:
RewriteRule ^(.*)$ /index.php?/$1 [L]
And boom. 和繁荣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.