duanri1985 2014-08-28 11:34
浏览 50

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

Disclaimer : know nothing about mode rewriting

I'v a simple .htacces the code is below:

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.

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.

By the way I've also added this <base href="/" /> line aswell in my html in <head> section. I don't know what is the issue seems to be any Idea?

  • 写回答

1条回答 默认 最新

  • duankuixi1930 2014-08-28 11:40
    关注

    Try use this code but u have to put your folder name after

    RewriteBase /CodeIgniter/ in 9th line.

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题