홈 서버에서 몇 가지를 호스팅하고 있지만 IP 주소가 자주 변경됩니다. 나는 도메인 이름이 없기 때문에 사람들에게 북마크 할 것을 줄 수는 없습니다. 이 문제를 해결하기 위해 HTML 파일을 DropBox에 뱉어내는 작은 Perl 스크립트를 만들어 사람들이 북마크 할 수 있도록했습니다. 이것이 최선의 해결책은 아니지만 지금까지 작동하는 것 같습니다.
문제는 더 멋지게 만들고 싶습니다. 내가 원하는 것은? path = wiki 같은 선택적 쿼리 문자열이 있고 실제로로드되면 자동으로 http : // (my_ip) / wiki로 리디렉션됩니다 .
불행히도 나는 리디렉션을 발생시키는 방법도 모르고이 답변을 얻은 사람을 보지 못했습니다. 특히 그와 같은 선택적이고 역동적 인 것입니다. 비록 내가 올바르게 이해한다면 간단해야합니다.
순전히 html로 나는 그것이 일어나는 것을 보지 않는다.
그러나 자바 스크립트로 할 수 있습니다. 어쨌든 사용자 정의 html 페이지를 뱉어 내면 아래 예제에서 targetUrl의 ipadres를 바꿀 수 있습니다.
<!DOCTYPE html>
<html>
<head>
<title>Test redirect</title>
<script type="text/javascript">
var targetUrl = 'http://127.0.0.1';
function querystring(paramName) {
var url = document.location.href, params, param, i, reply = {}, name, value;
if (url.indexOf('?') < 0) {
return null;
}
params = url.split('?')[1].split('&');
for (i = 0; i < params.length; i++) {
param = params[i].split('=');
name = (param[0] || '').toLowerCase();
value = param[1] || '';
if (typeof paramName === 'undefined' || paramName.toLowerCase() === name) {
if (typeof reply[name] !== 'undefined') {
if (typeof reply[name] === 'string') {
reply[name] = [ reply[name], value ];
} else {
reply[name].push(value);
}
continue;
}
reply[name] = value;
}
}
return reply;
}
function redirect() {
var path = querystring('path');
if (path === null || typeof path.path === 'undefined' || typeof path.path !== 'string') {
document.location.href = targetUrl;
} else {
document.location.href = targetUrl + '/' + path.path;
}
}
</script>
</head>
<body onload="javascript:redirect()">
<h1>Redirecting to homesite</h1>
<p>You are being redirected, please wait while the page is loading!</p>
</body>
</html>
이 경우? path = wiki의 쿼리 문자열 매개 변수가 있으면 targetUrl로 리디렉션하고 경로 / wiki를 추가합니다.
hyenahome.html? path = wiki 대신 hyenahome.html # path : wiki를 사용하도록 업데이트
<!DOCTYPE html>
<html>
<head>
<title>Test redirect</title>
<script type="text/javascript">
var targetUrl = 'http://127.0.0.1';
function querystring(paramName) {
var url = document.location.href, params, param, i, reply = {}, name, value;
if (url.indexOf('#') < 0) {
return null;
}
params = url.split('#')[1].split('&');
for (i = 0; i < params.length; i++) {
param = params[i].split(':');
name = (param[0] || '').toLowerCase();
value = param[1] || '';
if (typeof paramName === 'undefined' || paramName.toLowerCase() === name) {
if (typeof reply[name] !== 'undefined') {
if (typeof reply[name] === 'string') {
reply[name] = [ reply[name], value ];
} else {
reply[name].push(value);
}
continue;
}
reply[name] = value;
}
}
return reply;
}
function redirect() {
var path = querystring('path');
if (path === null || typeof path.path === 'undefined' || typeof path.path !== 'string') {
return;
} else {
document.location.href = targetUrl + '/' + path.path;
}
}
</script>
</head>
<body onload="javascript:redirect()">
<h1>Redirecting to homesite</h1>
<p>You are being redirected, please wait while the page is loading!</p>
</body>
</html>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다