为什么我的 CGI 脚本不断将链接重定向到本地主机?
访问此页面http://online-file-sharing.net/tos.html并单击底部页脚链接之一。它将您重定向到地址栏中的本地主机。我不知道它为什么这样做。
这是我的整个网站围绕的主脚本:
upload.cgi
$ENV{PATH} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
($ENV{DOCUMENT_ROOT}) = ($ENV{DOCUMENT_ROOT} =~ /(.*)/);
# untaint. #$ENV{SCRIPT_NAME} = '/cgi-bin/upload.cgi';
use lib './perlmodules';
#use Time::HiRes 'gettimeofday';
#my $hires_start = gettimeofday();
my (%PREF,%TEXT) = ();
当有人访问根目录时,不会显示任何文件,尽管我有一个 .htaccess 文件说要打开位于我的根目录中的 upload.cgi 文件。
当我将浏览器直接指向 CGI 文件时,它可以工作,但它会再次将我带到本地主机。
我将此网站托管在我自己的服务器(即这台计算机)上,如果此信息有帮助,我会使用 XAMPP。我还使用 DynDNS 作为我的名称服务器。
我希望你能给我一些见解。
Visit this page http://online-file-sharing.net/tos.html and click one of the bottom footer links. It redirects you to your localhost in the address bar. I have no idea why it does this.
This is in the main script that my entire website revolves around:
upload.cgi
$ENV{PATH} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
($ENV{DOCUMENT_ROOT}) = ($ENV{DOCUMENT_ROOT} =~ /(.*)/);
# untaint. #$ENV{SCRIPT_NAME} = '/cgi-bin/upload.cgi';
use lib './perlmodules';
#use Time::HiRes 'gettimeofday';
#my $hires_start = gettimeofday();
my (%PREF,%TEXT) = ();
No file is displayed when someone visits the root directory, although I have a .htaccess file saying to open my upload.cgi file which is located in my root directory.
When I point my browser directly to the CGI file it works but it brings me to my localhost again.
I'm hosting this website on my own server, which is this computer, and using XAMPP if this information helps. I'm also using DynDNS as my nameservers.
I hope you can give me some insight.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,只要查看 HTML 的源代码就会发现 localhost 实际上是链接的一部分。使您的链接具有相关性。例如,如果我给你这个 URL:
http://localhost/foobar
它总是带你到本地主机。如果你的情况,你想要的是
/foobar
,表明它应该从当前主机的根目录开始,并添加 foobar 路径。Well, just looking at the source of the HTML reveals that localhost is actually part of the link. Make your links relative. For instance, if I gave you this URL:
http://localhost/foobar
It's always going to take you to localhost. If your case, what you want is
/foobar
, indicating that it should start at the root of whatever the current host is, and add add the foobar path it.你用什么来生成 HTML?很明显,您不是手写的,或者您已经有了问题的答案,但听起来您导致超链接计算不正确。您想要的是一个以 / 开头的链接,这意味着您已经所在的任何域的根目录,或者相对于当前目录的路径。
What are you using to generate HTML? It's fairly obvious you're not writing this by hand or you'd already have the answer to your question, but it sounds like you're causing the hyperlinks to be calculated incorrectly. What you want is a link starting with /, meaning the root of whatever domain you're already in, or a path relative to the current directory.