[英]Codeigniter : what if I want both URL with index.php and without index.php work
[英]codeigniter work only with index.php in the url
我有帶有路由的CI安裝
$route['signin']="auth/login";
$route['logout']="auth/logout";
$route['signup']="auth/register";
我的ci安裝位於www.domain.com/app/
當我轉到此url時,它路由到www.domain.com/app/signin/,但顯示
The requested URL /www.domain.com/app/signin was not found on this server.
但是當我手動插入index.php時
www.domain.com/app/index.php/signin
然后打開。
可能是什么問題?我已經配置了htaccess。
此ci安裝在另一台服務器上,我將其轉移到該新服務器上。我將基本url保留為空白。
htaccess代碼是
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
此ci安裝在另一台服務器上,我將其轉移到了新服務器上。
基於它在另一台服務器上的工作情況,新服務器似乎沒有配置AllowOverride
Apache設置來啟用htaccess,這意味着您的htaccess被禁用或忽略。 或者,新服務器是非Apache Web服務器,它根本無法識別htaccess。
您需要將此更新config.php
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = 'http://domain.com/app/';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = ''; // Remove index.php
現在.htaccess
RewriteEngine on
# RewriteBase /
RewriteBase /app/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
嘗試這個 :
RewriteEngine on
RewriteBase/app/
# Add www in the start of URL if user leave
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Prevent CI index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
# Prevent user access to the CI system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Prevent user access to the CI application folder
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
像這樣設置RewriteBase
RewriteBase/app/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.