【问题标题】:htaccess url maskinghtaccess 网址屏蔽
【发布时间】:2011-08-18 13:26:01
【问题描述】:

嘿,我是 htaccess 的总 niewbie。 在我的网站 (mysite.com) 上,我获得了一个链接,该链接将变量定向并发送到安全网站 (othersite.com/somepage.php?urlink='www.mysite.com') 上的页面。

如何编辑我的 htaccess 文件以将 othersite.com/somepage.php?urlink='www.mysite.com' 重写为 urlink 具有的任何值。

我的 htaccess 中有这个

Options +FollowSymlinks<br>
Options All -Indexes<br>
Options Indexes Includes FollowSymLinks ExecCGI
RewriteEngine on
RewriteRule ^&urlink=(.*) http://$1 [P]

【问题讨论】:

    标签: .htaccess url masking


    【解决方案1】:

    好奇。认为它不会那样工作;如果您在其他服务器上请求页面,您自己的 htaccess 不会为您提供解决方案。 (如果您自己可以访问/拥有 othersite.com,他们的 htaccess 可以做到)。

    相反,我会编写一个小的 PHP 文件,使用 HTTP_HEADER 重定向到 otherside.com。 因此,您可以告诉您的 htaccess 隐藏您的 php-Url。

    我是否正确理解了您的问题?

    <?php
    $myInputURL = $my_POSTURL;
    $myOtherSite = "http://www.otherside.com?urllink=";
    $myURL = $myOtherSite . $myInputURL;
    header("Location: ".$myURL);
    ?>  
    

    【讨论】:

    • 我确实可以访问 othersite.com。我提供的 htaccess 位于 othersite.com。
    【解决方案2】:

    RewriteRule 不能像这样直接使用查询字符串。

    例如,如果 URL 是 http://www.example.com/kitten.php?say=meow,那么 RewriteRule 只能匹配 kitten.php 部分。其他所有内容都可以通过 RewriteCond 进行匹配,例如:RewriteCond %{QUERY_STRING} ^urlink=(.*)

    请参阅文档:http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond


    在你的情况下,它可能是这样的(抱歉,我不知道你到底想要达到什么目的,因此我只是在编辑你现有的规则):

    Options Indexes Includes FollowSymLinks ExecCGI
    RewriteEngine on
    
    RewriteCond %{QUERY_STRING} ^urlink=(.+)$
    RewriteRule ^somepage\.php$ http://%1 [P]
    

    【讨论】:

    • 感谢各位的帮助。这就是我想做的。每当显示页面 amazingbiz.co.za/eshop/shopping/…" 时,它必须在地址栏中显示 www.mysite.com
    • 没有。我在mysite.com 上有一个产品页面,但要查看购物车,您必须转到amazingbiz.co.za/eshop/shopping/…。我想要的是购物车页面 url 显示产品页面的 url,如mysite.com/view_cart.php。看起来好像做不到
    • 在这种情况下你必须做其他方式:当用户转到www.mysite.com/view_cart.php时,你会显示amazingbiz.co.za/eshop/...的内容——这就是如何保持的方式地址栏中您想要的www.mysite.com。您可以尝试使用反向代理来执行此操作(搜索更多内容).. 或在您的 PHP 脚本中获取该 amazingbiz.co.za/eshop/... 的内容(使用 curl_* 函数)并显示为您自己的页面。你真的必须测试它——我认为这不会很容易实现。
    猜你喜欢
    • 2011-11-16
    • 2015-07-20
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    相关资源
    最近更新 更多