简体   繁体   中英

.htaccess (mod_rewrite) php redirection does not work

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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