PHP Redirect with Http Query String Variables

php redirect with HTTP query string variables

<?php
header("Status: 301 Moved Permanently");
header("Location:./content/index.html?". $_SERVER['QUERY_STRING']);
exit;
?>

PHP Redirect with query parameters

I modified Kasia Gogolek's answer so that it works for me. This is the solution to my question:

$fullUrl = $_SERVER[REQUEST_URI];
// split the url
$url = parse_url($fullUrl);
$url['path'] = "/test" . $url['path'];
// create the new url with test in the path
$newUrl = $url['path']."?".$url['query'];
header("Location:" .$newUrl);

How can I redirect back with query string?

If you're using Redirect::to() then is simple.

return Redirect::to('route_name?q='.$append_data)

If you want to use Redirect::back() then do these following

# Pass the value while redirecting
return Redirect::back()->with('query_data', 'some_data');

And add condition to your blade file.

@if(!empty(Session::get('query_data')) && Session::get('query_data') == 'some_data')
<script>
$(function() {
//Change the tab using javascript or
//use location.href to refresh after appending query params to url.
});
</script>
@endif

How to redirect url with query string to another url with a query string using .htaccess

You will need to use mod_rewrite here to be able to examine and capture values from QUERY_STRING.

RewriteEngine On

RewriteCond %{QUERY_STRING} (?:^|&)search=([^&]+) [NC]
RewriteRule ^page/?$ /?s=%1 [L,NC,R=302]

PHP Redirect / Get URL and Query String

Get the URI of hte page

$request_url=$_SERVER['REQUEST_URI'];

output should be news/?p=1023

Explode the results

explode("/", $request_url, 2);

get the components after /news/ and then redirect

$link = $request_url[2]; //the second piece of the explode
header( 'Location: http://www.example.com/$link' ) ;

php redirect and querystring

$to must be urlencoded, but note that you giving a redirect script to anyone, so, any phisher can use it.

So, it would be better to store urls in the database and pass only an identifier.



Related Topics



Leave a reply



Submit