如何获取当前的URL?

时间:2014-04-25 04:08:17

标签: javascript php html

例如:

when I visit http://mywebsite.com/howtoloseweight/, click "part 1" link, I will be redirected to http://mywebsite.com/howtoloseweight/1

 when I visit http://mywebsite.com/howtoloseweightfast/, click "part 1" link, I will be redirected to http://mywebsite.com/howtoloseweightfast/1

怎么做?谢谢!

4 个答案:

答案 0 :(得分:0)

在JavaScript中:

window.location 

有关详细信息,请参阅以下链接:

https://developer.mozilla.org/en-US/docs/Web/API/Window.location

答案 1 :(得分:0)

您需要执行两个步骤:

  1. 打开文本编辑器并在其中添加最新行

    RewriteEngine On

    RewriteRule ^ howtoloseweight / 1 $ /howtoloseweight/1.html [L]

  2. 将文件保存为" .htaccess"

  3. 建立链接<a href="/howtoloseweight/1">part 1</a>。这样做的链接将根据您的意愿转到http://mywebsite.com/howtoloseweight/1

答案 2 :(得分:0)

在您的第一页(http://mywebsite.com/howtoloseweight)的第1部分链接上进行如下链接

<a href="http://mywebsite.com/howtoloseweight/1">part 1</a>

<a href="./1">part 1</a>

在第二页(http://mywebsite.com/howtoloseweightfast/)上建立如下链接

<a href="http://mywebsite.com/howtoloseweightfast/1">part 1</a>

<a href="./1">part 1</a>

FYI : - &#34;。&#34;总是指当前的位置。

答案 3 :(得分:0)

PHP:

<?php
function curPageURL() {
 $pageURL = 'http';
 if(isset($_SERVER["HTTPS"])){if (($_SERVER["HTTPS"]) == "on") {$pageURL .= "s";}}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
echo curPageURL();
?>