简体   繁体   English

.htaccess(mod_rewrite)php重定向不起作用

[英].htaccess (mod_rewrite) php redirection does not work

Disclaimer : know nothing about mode rewriting 免责声明:对模式重写一无所知

I'v a simple .htacces the code is below: 我是一个简单的.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]

I've some internal redirection, if user successfull logged in it should redirect to another folder's index file. 我有一些内部重定向,如果用户成功登录它,则应该重定向到另一个文件夹的索引文件。 it was work fine before adding this .htaccess file. 添加此.htaccess文件之前,一切正常。

This is how i'm redirecting : 这就是我重定向的方式:

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

redirectTO('agent/index.php');

EDIT: Redirection has stopped working after adding that mode rewrite code. 编辑:添加该模式重写代码后,重定向已停止工作。 i don't know if i need all of that code I've copied from a another stack overflow post. 我不知道我是否需要从另一个堆栈溢出后复制的所有代码。 if you think some of the .htaccess code is irrelevant please feel free to advise on that too. 如果您认为某些.htaccess代码无关紧要,请随时提出建议。

By the way I've also added this <base href="/" /> line aswell in my html in <head> section. 顺便说一下,我还在<head>部分的html中也添加了<base href="/" />行。 I don't know what is the issue seems to be any Idea? 我不知道问题出在哪里,这是什么主意?

Try use this code but u have to put your folder name after 尝试使用此代码,但您必须在后面加上文件夹名称

RewriteBase /CodeIgniter/ in 9th line. 第9行中的RewriteBase / CodeIgniter /。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM