Redirect URL without parameter

2019-08-30 18:15发布

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.

1条回答
叛逆
2楼-- · 2019-08-30 19:09

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();
    }

?>
查看更多
登录 后发表回答