2014-08-28 102 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