RewriteEngine On
RewriteBase /path/learn_ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /path/learn_ci/$1 [L]
在我的.htaccess文件上方如何配置它。
答案 0 :(得分:1)
在您的.htaccess文件中放置代码。
RewriteEngine On
RewriteBase /path/learn_ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|asset|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
在 application / config / config.php 上面放置代码
$config['base_url'] = 'http://yourdomain.com/';
$config['index_page'] = '';
这对你有用。
享受...! :)
答案 1 :(得分:0)
这是我在大多数CodeIgniter项目中使用的,从未遇到过问题。
您需要调整RewriteBase。它从Web服务器/ www / your_project的根目录开始将更改为htaccess文件中的/ your_project /。
另外,请确保已启用mod_rewrite。
How to enable mod_rewrite for Apache 2.2
CodeIgniter htaccess and URL rewrite issues
此外,您需要从CodeIgniter安装中位于config.php的$ config ['index_page'] ='index.php'中删除index.php。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your_project/
#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 $1 !^(index\.php|img|font|css|temp|js|robots\.txt|favicon\.ico)
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>
答案 2 :(得分:0)
这应该是项目根文件夹中的htaccess文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / yourproject
#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>
您可以将config.php中的index.php删除为:$config['index_page'] = '';