简体   繁体   中英

.htaccess: Want query string added to 301 Redirect to same url

Example: When someone visits this URL

http://example.com/site/register

I'd like this query string to be automatically added:

http://example.com/site/register?destination=thankyou

I've tried the following in my .htaccess file:

Redirect 301 /site/register /site/register?destination=thankyou

But this creates an infinite redirect loop.

I've crawled the web for hours for a solution but to no avail. Thanks in advance.

if register is PHP, use something like:

<?php
  if(!array_key_exists('destination',$_GET))
    header('Location: '.http_build_query(
        array_merge($_GET,array('destination'=>'thankyou')));

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