修剪与htaccess的URL查询字符串 [英] trim url query string with .htaccess
问题描述
在我的地盘我使用一个会话ID访问一个网页形式的内容时。在URL中的SessionID不能正常显示,因为它是通过jQuery的.load访问这样的URL不会改变。以上引用的页面需要通过直接一些外域进行访问。 我用下面的PHP在表单页面的顶部,显示整个网页。
On my site I use a session id when accessing a pages form content. The sessionid in the url isn't normally shown because it's accessed through jQuery .load so the url doesn't change. The page in reference above needs to be accessed by some outside domains directly. I have used the following PHP at the top of the form page, to show the entire page.
<?php
$code = $_GET['sessionid'];
$referrer = $_SERVER['HTTP_REFERER'];
if(strcmp( $code , 'XXXXX' ) !=0) {
if (preg_match("/alloweddomain.com/",$referrer)) {
header('Location: http://www.mydomain.com/desiredpage.php?sessionid=XXXXX');
} else {
header("Location: http://www.mydomain.com/otherpage.php");
}
}
?>
有没有用的.htaccess的方式来删除会话ID?我试过以下,但得到500内部服务器错误。
Is there a way with .htaccess to remove the session ID? I've tried the following but get 500 Internal Server Errors.
RewriteEngine On
RewriteBase /
"lots of 301 redirects"
HTTP_REFERER variable RewriteCond %{HTTP_REFERER} !aloweddomain.com RewriteCond %{QUERY_STRING} !="sessionid=XXXXX" RewriteRule .* /desiredpage.php? [R=301,L]
的*** 修改的 * 的**的 * 的 用这个,填写相应的信息
***EDIT**** used this, filling in the appropriate details
RewriteCond %{HTTP_REFERER} !**aloweddomain.com** [OR]
RewriteCond %{QUERY_STRING} !=sessionid=**XXXXX**
RewriteRule .* /**desiredpage**.php? [R=301,L]
只是让FF的错误,它不能完成重定向
just get FF error that it can't complete redirect
推荐答案
您忘了换行
RewriteCond %{HTTP_REFERER} !aloweddomain.com [OR]
RewriteCond %{QUERY_STRING} !=sessionid=XXXXX
RewriteRule .* /desiredpage.php? [R=301,L]
这将重定向所有的URL不来自aloweddomain.com或者没有QUERY_STRING。我算了一下 [OR]
如果有,也不 [OR]
然后再这两个条件必须是真实的。
This will redirect all url's that don't came from aloweddomain.com or don't have Query_String. I forget about [OR]
if there is nor [OR]
then then the two conditions must be true.
如果desiredpage.php很简单,即表明您不能访问该网站,然后页面,您可以把403禁止,而不是重定向
and if desiredpage.php is simply page that show that you can't access the site then you can put 403 Forbidden instead of redirect
RewriteRule .* - [F,L]
如果您想从AJAX或自定义域调用它。
If you want to call it from AJAX or custom domain.
if (preg_match('/domain.com/', $_SERVER['HTTP_REFERER']) ||
$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
// allowed
header('Location: http://www.mydomain.com/desiredpage.php');
} else {
// not allowed
header('Location: http://www.mydomain.com/otherpage.php');
}
$ C $下 desiredpage.php
if (!(preg_match('/domain.com/', $_SERVER['HTTP_REFERER']) ||
$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {
header('Location: http://www.mydomain.com/otherpage.php');
}
这篇关于修剪与htaccess的URL查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!