-1

Inside a very simple HTML-only website, how to make this happen :

On a page Mysite.com/ABC/mypage.html

Action ; visitor clic on a link, goes to

Mysite.com/XYZ/mypage.html

So with an easy text link like <a href=""></a>, change the actual pages's previous directory only ?

Could be good easy solution for easy language switch

revv86
  • 11
  • 2
  • 9
  • What do you mean by “keep same page url as simple HTML?” If you keep the same URL, you would be linking to the page itself, so you must means something else. There is a large number of ways that the question could be interpreted. – Jukka K. Korpela Apr 20 '17 at 03:48

3 Answers3

0

You can do this:

<a href="../XYZ/mypage.html">

You can change your file name to index.html, or anything else that you set for the default page names in your web browser and you could simply do:

<a href="../XYZ/">
Kamyar Infinity
  • 2,711
  • 1
  • 21
  • 32
0

Is this what you are looking for?

<a href="/XYZ/mypage.html">Text</a>

This is because URLs which start with a forward-slash (/) are called 'absolute paths', and refer to the root, i.e. relative to mysite.com

Alternatively, if you want to affect the next directory up only, you can use the following:

<a href="../XYZ/mypage.html">Text</a>

This is because .. refers to the parent directory. So if you had a page at example.com/folder1/ABC/mypage.html and you wanted that page to link to example.com/newpages/XYZ/mypage.html, you could do:

<a href="../../newpages/XYZ/mypage.html">Text</a>

There are lots of examples and tutorials online, e.g. https://www.w3.org/TR/WD-html40-970917/htmlweb.html

Matt Styles
  • 581
  • 1
  • 4
  • 14
0

For HTML-only, I believe Kamyar Infinity's comments regarding rewrite rules are your best bet. However, if you're considering using PHP, this might do the trick. It will print the current file name to the after of the desired directory:

 <a href="/xzy/<?php echo basename($_SERVER['PHP_SELF']); ?>">text</a>

Alternatively we can use javascript to manipulate the href for this link (without using PHP at all):

<a href="/xyz/">text</a>

<script>
  //Get current Pagename
  var currentPage = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);

  //Change href for link
  document.querySelector('a[href="/xyz/"]').setAttribute('href', '/xyz/'+ currentPage);
</script>
Jeffhowcodes
  • 406
  • 3
  • 9