-6

For example:

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

How to do that ? Thanks !

4 Answers4

0

In JavaScript:

window.location 

See the link below for more info:

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

Kyo
  • 964
  • 5
  • 10
0

You need to do 2 steps:

  1. open your text editor and put thest lines in it

    RewriteEngine On

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

  2. save file as ".htaccess"

  3. make a link <a href="/howtoloseweight/1">part 1</a>. Doing this the link will go to http://mywebsite.com/howtoloseweight/1 as you wish.
Wilf
  • 2,235
  • 5
  • 33
  • 77
0

on the part 1 link of your first page (http://mywebsite.com/howtoloseweight) make the link as below

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

or

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

on the second page (http://mywebsite.com/howtoloseweightfast/) make the link as below

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

or

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

FYI:- "." always refers the current location.

Tharaka Nuwan
  • 460
  • 1
  • 5
  • 20
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();
?>
anik4e
  • 493
  • 8
  • 16