[英]CodeIgniter Mod_Rewrite issues
Having issues removing index.php? 在删除index.php时遇到问题? from the URL: 从URL:
http://localhost/index.php?/reset_password
With htaccess file: 使用htaccess文件:
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
CI Settings: 配置项设置:
$config['uri_protocol'] = 'AUTO';
I looked at the other threads on here with similar problems but none of their htaccess files work. 我在这里查看了其他具有类似问题的线程,但是它们的htaccess文件均不起作用。 Am I missing a setting? 我是否缺少设置?
I've never seen that .htaccess
setup before, although it may work. 我以前从未见过.htaccess
设置,尽管它可能有效。 I've used this for every CI project I've done, give it a try: 我已经在完成的每个CI项目中都使用了此功能,请尝试一下:
<IfModule mod_rewrite.c>
RewriteEngine on
# If the start of the URL doesn't match one of these...
RewriteCond $1 !^(index\.php|robots\.txt|assets|cache|themes|uploads)
# Route through index.php
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Add don't forget this in config.php
: 添加不要忘记这在config.php
:
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
And remember: This will not "remove" index.php
from your URL automatically, but rather route the request through it if it isn't present. 请记住:这不会自动从您的URL中“删除” index.php
,而是通过不存在的请求来路由请求。 If you have hardcoded links with index.php
in them, they'll have to be changed or you'll need additional .htaccess
configuration. 如果您在其中包含带有index.php
硬编码链接,则必须更改它们,否则您将需要其他.htaccess
配置。 If you are using the CI url functions like base_url()
, site_url()
, and anchor()
, they won't use index.php
if you have it blank in your config above. 如果您使用的是诸如base_url()
, site_url()
和anchor()
类的CI url函数,则如果在上面的配置中将其空白,它们将不会使用index.php
。
This code works for me: 该代码对我有用:
If name of my site is codeIgniter_ci_intro 如果我的网站名称是codeIgniter_ci_intro
I used code in .htaccess 我在.htaccess中使用了代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /codeIgniter_ci_intro//index.php/$1 [L]
and I changed in config.php 我在config.php中更改了
$config['index_page'] = '';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.