dongzhang0418 2014-08-19 15:47
浏览 66
已采纳

PHP重定向在mod_rewrite(.htaccess)文件后停止工作

My redirect logic has stopped working ever since I've put the following code

Options -Indexes
ErrorDocument 404 /site3/public/admin/filenotfound.php

RewriteEngine On
RewriteBase /site3/public/admin/

RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [L]

RewriteCond %{THE_REQUEST} \s([^.]+?)(?:\.php)?\?caseid=([^&\s]+)?\&picid=([^&\s]+)\s [NC]
RewriteRule ^ %1/caseid/%2/picid/%3/? [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/caseid/([^/]+)/picid/([^/]+)/?$ $1.php?caseid=$2&picid=$3 [L,NC,QSA]

RewriteCond %{THE_REQUEST} \s([^.]+?)(?:\.php)?\?caseid=([^&\s]+)\s [NC]
RewriteRule ^ %1/caseid/%2/? [R=302,L,NE]

RewriteCond %{THE_REQUEST} \s([^.]+?)(?:\.php)?\?search=([^&\s]+)\s [NC]
RewriteRule ^ %1/search/%2/? [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/caseid/([^/]+)/?$ $1.php?caseid=$2 [L,NC,QSA]

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

this is how i'm redirecting my page

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

redirectTO('page.php');

I'm not a very good of mode rewriting therefore i cannot work out where the issue is please advise me what should, by the way they work fine if remove my .htaccess file doesn't work if put that file back on.

Any Idea?

  • 写回答

2条回答 默认 最新

  • dounaidu0204 2014-08-19 15:52
    关注

    use full path of your of the URL i.e. www.example.com/page.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?