重定向标头功能不起作用

时间:2021-10-24 11:01:58

I have this htaccess filecontent:

我有这个htaccess文件内容:

Options +FollowSymLinks 
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^admin/([a-zA-Z]+)/?([a-zA-Z0-9/]*)$ public/admin/index.php?page=$1&query=$2 [L]
RewriteRule ^([a-zA-Z]+)/?([a-zA-Z0-9/]*)$ public/index.php?page=$1&query=$2 [L]

And now im trying to make a redirection depending on a session, very simple stuff. I have a Controller with this function:

现在我试图根据会话进行重定向,非常简单的东西。我有一个具有此功能的控制器:

protected function redirect($url) {
    header("Location: http://localhost:8888/myproject/" . $url, true);
    exit(); 
}

The ClientController that extends Controller has the page function

扩展Controller的ClientController具有页面功能

private function user_page() {
   $this->redirect("homepage");  //Not working...
}

I have tried different ways of writing the location path like

我已经尝试过不同的编写位置路径的方法

Location: localhost:8888/myproject/" . $url,
Location: /myproject/" . $url,

Now after reading all posts on *, I see none of these solutions have worked for me..

现在阅读了*上的所有帖子后,我发现这些解决方案都没有对我有用..


Edit: the solution to this can be seen on header redirect to Location does not work

编辑:解决方案可以在标题重定向到位置上看到不起作用

1 个解决方案

#1


1  

After getting an answer from header redirect to Location does not work I found that the problem was some row of spaces that had been inputted after ?> in the Controller, so it took a while to notice it.

从标题重定向到位置获得答案后无法正常工作我发现问题是在控制器中?>之后输入的一些空格行,所以需要一段时间才能注意到它。


Clarification: If you have the same problem make sure you have line numbers set and see if you can see any line numbers after the file content. If there is you may have blank lines after aswell. Just delete these. Needless to say, the same goes for linenumbers before filecontent

澄清:如果您遇到同样的问题,请确保设置了行号,并查看是否可以在文件内容后看到任何行号。如果有的话,你可能还有空行。只需删除这些。毋庸置疑,在文件内容之前,亚麻布也是如此

#1


1  

After getting an answer from header redirect to Location does not work I found that the problem was some row of spaces that had been inputted after ?> in the Controller, so it took a while to notice it.

从标题重定向到位置获得答案后无法正常工作我发现问题是在控制器中?>之后输入的一些空格行,所以需要一段时间才能注意到它。


Clarification: If you have the same problem make sure you have line numbers set and see if you can see any line numbers after the file content. If there is you may have blank lines after aswell. Just delete these. Needless to say, the same goes for linenumbers before filecontent

澄清:如果您遇到同样的问题,请确保设置了行号,并查看是否可以在文件内容后看到任何行号。如果有的话,你可能还有空行。只需删除这些。毋庸置疑,在文件内容之前,亚麻布也是如此