重定向URL无参数 [英] Redirect URL without parameter

查看:125
本文介绍了重定向URL无参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做下面的,我不知道这是用PHP,Javacript或者如果它在htaccess文件所做的一切。

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.

当有人签署了我的网站上,他们得到了的WebID分配的,他们可以访问一个页面,我不想过没有说要的WebID访问某些内容。

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.

例: 1)游客签约 2)我将访问者这样的HTTP链接:// www.mysite.com/paid/report.php?webid=123456 3)访问者点击链接,查看报告

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

但如果访问者输入HTTP:// www.mysite.com/paid/report.php没有的WebID参数我需要他们被重定向到不同的页面,例如:HTTP:// www.mysite。 COM / signup.php

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

我假定这一点是需要在htaccess文件做了,但我不知道怎么样。

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

感谢你。

推荐答案

好了,你可以用的.htaccess像这样做

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]

但为什么不使用PHP

but why not use PHP

<?php

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

?>

这篇关于重定向URL无参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆