user1251762
user1251762

Reputation: 119

Redirect URL without parameter

I need to do the following and I'm not sure if this is done with PHP, Javacript or if its done in the htaccess file.

When somebody signs up on my site they get a "webid" assigned and they can access a page with some content that i don't want to be accessed without that webid.

Example: 1) visitor signs up 2) I send the visitor a link like this http:// www.mysite.com/paid/report.php?webid=123456 3) visitor clicks on the link and views the report

but if the visitor enters http:// www.mysite.com/paid/report.php without the "webid" parameter I need them to be redirected to a different page, for example http:// www.mysite.com/signup.php

I'm assuming this is something that needs to be done in htaccess file, but I'm not sure how.

Thank you.

Upvotes: 0

Views: 1299

Answers (1)

scibuff
scibuff

Reputation: 13755

Well, you can do it with .htaccess like so

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/report\.php$
RewriteCond %{QUERY_STRING} !^webid=([0-9]*)$
RewriteRule ^(.*)$ http://example.com/signup.php [R=302,L]

but why not use PHP

<?php

    if ( !isset( $_REQUEST['webid'] ) ){
        // redirect
        header( 'Location: http://example.com/signup.php' );
        exit();
    }

?>

Upvotes: 2

Related Questions