Codeigniter Htaccess 和 URL 重定向问题
Codeigniter Htaccess and URL Redirect issues
我正在尝试在 CodeIgniter 上使用 .htaccess
,但它不起作用。
我已经设置了:
AllowOverride All
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
我在 Windows 上使用 XAMPP。
我的.htaccess
:
RewriteEngine On
RewriteCond !^(index\.php|images|scripts|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]
我的 URL 仍然包含 index.php
,如果我尝试手动删除它,它会 returns 出现 404 错误
我的另一个问题是我的登录页面:每当我登录时,我的 URL 卡在检查页面上。
我想知道如何重写我的 URL 以更改到主页而不是停留在检查页面上。
public function check(){
$this->load->model('check');
$logcheck = $this->check->check($this->input->post('username'),$this->input->post('password'));
if($logcheck == "admin"){
$this->load->view('home');
}else{
$this->load->view('login');
}
}
我发现如果你去这里 http://www.insiderclub.org/downloads 然后点击 link "HERE IT IS" 下载 htaccess zip 文件夹,大约有 5 个不同的适合 codeigniter对于 htaccess
不确定 AllowOverride All 在哪里发挥作用?
还有
$config['uri_protocol'] = 'REQUEST_URI';
制作
$config['uri_protocol'] = 'AUTO';
$config['base_url'] = 'http://localhost/yourproject/';
$config['index_page'] = '';
确保您已配置 route.php
主 htaccess 根目录。您不需要触摸另一个 .htaccess
您在 zip 中找到的第一个就是这个
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
我的 xampp 和 codeigniter 2 & 3 似乎工作正常,但请尝试下载。
这是用于 htaccess 的 zip 文件夹中的第二个,考虑更多用于 wamp 等。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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?/ [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?/ [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?/ [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>
这个简单的 .htaccess 将删除您的 index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
像这样更改您的检查功能
public function check(){
$this->load->model('check');
$logcheck = $this->check->check($this->input->post('username'),$this->input->post('password'));
if($logcheck == "admin"){
//may be you need to set login credential into session
redirect('Phonebook/home/');
//$this->load->view('home');
}else{
$this->load->view('login');
}
}
你的主页功能将是这样的
public function home(){
//remember you need to check login validation from session
$this->load->view('home');
}
要使用 redirect
函数,请记住您已加载 url
助手。
可能对你有帮助
我正在尝试在 CodeIgniter 上使用 .htaccess
,但它不起作用。
我已经设置了:
AllowOverride All
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
我在 Windows 上使用 XAMPP。
我的.htaccess
:
RewriteEngine On
RewriteCond !^(index\.php|images|scripts|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]
我的 URL 仍然包含 index.php
,如果我尝试手动删除它,它会 returns 出现 404 错误
我的另一个问题是我的登录页面:每当我登录时,我的 URL 卡在检查页面上。
我想知道如何重写我的 URL 以更改到主页而不是停留在检查页面上。
public function check(){
$this->load->model('check');
$logcheck = $this->check->check($this->input->post('username'),$this->input->post('password'));
if($logcheck == "admin"){
$this->load->view('home');
}else{
$this->load->view('login');
}
}
我发现如果你去这里 http://www.insiderclub.org/downloads 然后点击 link "HERE IT IS" 下载 htaccess zip 文件夹,大约有 5 个不同的适合 codeigniter对于 htaccess
不确定 AllowOverride All 在哪里发挥作用?
还有
$config['uri_protocol'] = 'REQUEST_URI';
制作
$config['uri_protocol'] = 'AUTO';
$config['base_url'] = 'http://localhost/yourproject/';
$config['index_page'] = '';
确保您已配置 route.php
主 htaccess 根目录。您不需要触摸另一个 .htaccess
您在 zip 中找到的第一个就是这个
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
我的 xampp 和 codeigniter 2 & 3 似乎工作正常,但请尝试下载。
这是用于 htaccess 的 zip 文件夹中的第二个,考虑更多用于 wamp 等。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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?/ [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?/ [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?/ [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>
这个简单的 .htaccess 将删除您的 index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
像这样更改您的检查功能
public function check(){
$this->load->model('check');
$logcheck = $this->check->check($this->input->post('username'),$this->input->post('password'));
if($logcheck == "admin"){
//may be you need to set login credential into session
redirect('Phonebook/home/');
//$this->load->view('home');
}else{
$this->load->view('login');
}
}
你的主页功能将是这样的
public function home(){
//remember you need to check login validation from session
$this->load->view('home');
}
要使用 redirect
函数,请记住您已加载 url
助手。
可能对你有帮助