我知道这个问题已被多次询问过。 但是,我仍然无法摆脱index.php网址。它阻止我直接访问我的控制器。
我目前正在使用CodeIgniter 2.2.2
以下是我的.htaccess
文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
应用/配置:
// Find the below code
$config['uri_protocol'] = "AUTO"
// Replace it as
$config['uri_protocol'] = "REQUEST_URI"
任何想法?提前感谢您的时间。
答案 0 :(得分:1)
在.htacess中使用以下代码
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]
答案 1 :(得分:1)
试试这个..
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]
答案 2 :(得分:1)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
然后转到config.php并删除index.php
$config['index_page'] = 'index.php';
//change it to
$config['index_page'] = '';
答案 3 :(得分:1)
如果使用wamp,请确保启用了apache mod rewrite。
这个htaccess适用于wamp或xampp
:host {
all: initial;
}
确保它放在主目录上。
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
答案 4 :(得分:1)
Index.php文件将默认包含在您的网址中。
示例:强>
example.com/index.php/controller
您如何改变?
您可以使用.htaccess中的重写规则从URL
中删除index.php来自User Guide的示例:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
使用“否定”方法,除了指定的项目外,所有内容都被重定向。
最后一件事是让你使用index_page作为空位置application / config / config.php:
$config['index_page'] = '';
最后,如果您仍然面临问题更改uri_protocol AUTO
至REQUEST_URI
。
$config['uri_protocol'] = "REQUEST_URI";
答案 5 :(得分:0)
这对我有用。
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
答案 6 :(得分:0)
在你的.htaccess
上RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
和$config['index_page'] = '';
为我工作
答案 7 :(得分:-1)
最后解决了我的问题。我想与大家分享我的答案。 我目前正在使用mac,我将.htaccess文件重命名为htaccess.txt 并在htaccess中包含以下代码: RewriteEngine On
#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 %{ENV:REDIRECT_STATUS} ^$
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
然后确保Apache正在读取htaccess.txt文件:
在httpd.conf
进入extra / httpd-default.conf文件并更改以下代码行:AccessFileName .htaccess
到AccessFileName htaccess.txt
重启Apache服务器
在配置中,确保将“base_url”留空(索引页仍然可以存在,无关紧要)。并且$ config ['uri_protocol'] ='REQUEST_URI';
希望这可以帮助其他人!