Redirect with header function not working

I have this htaccess filecontent:

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 I'm trying to do a session-specific redirection, very simple stuff. I have a controller with this function:

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

ClientController, which extends the controller, has a page function

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

I tried different ways to record the location path, for example

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

Now, after reading all the posts in stackoverflow, I see that none of these solutions worked for me.


Edit: a solution to this can be seen on header redirection in Location not working

+4
source share
1 answer

After receiving a response from the header redirection in Location does not work . I found that the problem was some string of spaces introduced after ?> In the controller, so it took a while to notice this.


Explanation: If you have the same problem, make sure you have the line numbers set and see if you can see the line numbers after the contents of the file. If there is, you may have blank lines after. Just delete them. Needless to say, the same goes for tape materials in front of file contents

+1
source

Source: https://habr.com/ru/post/1490108/


All Articles