2014-08-28 78 views
0

免責聲明:一無所知模式改寫的.htaccess(mod_rewrite的)PHP重定向不起作用

心中已經簡單.htacces的代碼如下:

Options -Indexes 
ErrorDocument 404 /filenotfound.php 

RewriteEngine On 
RewriteBase/

### hide .php extension snippet  
## To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} \s([^.]+)\.php [NC] 
RewriteRule^%1/ [R=302,L,NE] 

## add a trailing slash 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE] 

## To internally forward /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+?)/?$ $1.php [L] 

我有一些內部重定向,如果用戶成功登錄,它應該重定向到另一個文件夾的索引文件。在添加這個.htaccess文件之前它工作正常。

這是如何我重定向:

function redirectTO($url = null){ 
    if($url != null){ 
     header("Location:{$url}"); 
     exit(); 
    } 
} 

redirectTO('agent/index.php'); 

編輯:重定向已停止並稱模式重寫代碼之後的工作。我不知道是否需要從另一個堆棧溢出文章中複製的所有代碼。如果您認爲某些.htaccess代碼無關緊要,請隨時就此提出建議。

順便說一句,我也加了這<base href="/" />線以及我的HTML <head>部分。我不知道這個問題似乎是什麼想法?

+1

**不起作用**您能更加明確嗎?否則,我們不能幫你 – 2014-08-28 11:36:48

+0

好吧@JustinIurman這個重定向已經停止工作後,該htaccess文件..順便讓我編輯我的帖子以及 – Sharif 2014-08-28 11:38:08

+0

什麼是在第一個地方添加.htaccess文件的原因是什麼?你究竟在努力實現什麼? – arco444 2014-08-28 12:09:51

回答

2

嘗試使用此代碼但你必須把你的文件夾名後

RewriteBase /笨/在第9行。

<IfModule mod_rewrite.c> 
    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 /mypage/test1/ 
    RewriteBase /CodeIgniter/CodeIgniter/ 
    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> 
+0

在您的代碼中,將您的文件夾名稱安裝在第4行的codeigniter中。 – Kakshak 2014-08-28 11:42:13

+0

讓我試試@Kakshak – Sharif 2014-08-28 11:42:21

+0

不,不行不行 – Sharif 2014-08-28 11:45:30