[英]Codeigniter Htaccess and URL Redirect issues
我試圖在CodeIgniter上使用.htaccess
,但它無法正常工作。
我已經設定:
AllowOverride All
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
我在Windows上使用XAMPP。
我的.htaccess
:
RewriteEngine On
RewriteCond $1 !^(index\.php|images|scripts|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
我的URL仍包含index.php
,如果我嘗試手動刪除它,則會返回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');
}
}
這個簡單的.htaccess將刪除你的index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [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
helper。
可能對你有所幫助
我發現如果你去這里http://www.insiderclub.org/downloads然后點擊鏈接“這就是”下載htaccess zip文件夾,大約有5種不同的適合代碼簽名用於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 $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [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?/$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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.