0
我想爲我的網站「漂亮的網址」。我正在尋找使用.htaccess
,我已經嘗試了很多版本。CodeIgniter htaccess重定向url問題
現在我有這樣的:
IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mysite
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>
所以這消除index.php
從URL。起初,這是確定的,但
這裏是我的config.php
:
$config['base_url'] = 'localhost/mysite/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
我的.htaccess文件是在我的應用程序的根。 folder img
我需要登錄管理頁面,所以localhost/mysite/admin
是我的管理網站的網址。
public function index()
{
// $this->session->unset_userdata('logged_in'); session_destroy();
$data['sitename']="Varkocs Old Pub";
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
$this->load->view('admin/home_view', $data);
}
else
{
//If no session, redirect to login page
//redirect('login', 'refresh');
$this->load->helper(array('form', 'url'));
$this->load->view('admin/login',$data);
}
}
public function logout()
{
$this->session->unset_userdata('logged_in');
session_destroy();
redirect('', 'refresh');
}
這是我的管理員控制器。我在這裏嘗試,如果登錄我加載home_view
,否則login
視圖。
<div id="" class="container-fluid ">
<div id="" class="row">
<div id="" class="col-md-4 text-center admin_container">
<h2><?php echo $sitename;?><h4>belépés az admin felületre</h4></h2>
<?php echo validation_errors('<p class="bg-danger">','</p>');?>
<form action="verifylogin" method="post" accept-charset="utf-8">
<div class="form-group">
<label for="username">Username:</label>
<input class="form-control" placeholder="" type="text" size="20" id="username" name="username"/>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input class="form-control" placeholder="password" type="password" size="20" id="passowrd" name="password"/>
</div>
<input class="btn btn-warning btn-lg btn-block" type="submit" value="Login"/>
</form>
</div>
</div>
這是登錄視圖。我不能在這裏使用:
echo form_open('verifylogin');
因爲它返回了錯誤的URL。
所以我寫HTML:
<form action="verifylogin" method="post" accept-charset="utf-8">
使用CodeIgniter的表單驗證工作。但之後的重定向不起作用。
$this->load->helper(array('form', 'url'));
if($this->form_validation->run() == FALSE)
{
//Field validation failed. User redirected to login page
$data['sitename']="Varkocs Old Pub";
$this->load->view('admin/login',$data);
}
else
{
//Go to private area
redirect('admin', 'refresh');
}
我已經嘗試了很多方法來解決這個問題,但我失敗了。
我的問題是重定向。 //轉到私有區域 重定向('admin','refresh');我設置了基本url:localhost/mysite,我想要去localhost/mysite/admin控制器。我能做什麼? – user2028782
對不起,我認爲當你說它不工作時,重定向給了一個空白頁。如果它導致錯誤的頁面,你可能需要調整你的base_url爲絕對url:'$ config ['base_url'] ='http:// localhost/mysite /';' – Gentle153