Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 129471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:47:41+00:00 2026-05-11T05:47:41+00:00

I am programming a small script using PHP and regular expressions The aim of

  • 0

I am programming a small script using PHP and regular expressions

The aim of this script is to extract all links in a page and convert these links to absolute- when it is relative – I figured how does relative links works but their are some questions also

lets say we have this page http://www.example.com/xxx1/xxx2/xxx3.html if this page has the following links

index.html — the absolute link will be http://www.example.com/xxx1/xxx2/index.html

./index.html — the absolute link will be http://www.example.com/xxx1/xxx2/index.html

../index.html — the absolute link will be http://www.example.com/xxx1/index.html

/index.html — the absolute link will be http://www.example.com/index.html

so

index.html = will open in the current directory

./index.html = will also open in the current directory

../index.html = will open in the parent directory

/index.html = will open in the root directory

the problem is what if the URL is a search engine friendly?

say we have this URL

((case1)): http://www.example.com/xxx1/xxx2/xxx3/index/

or

((case2)): http://www.example.com/xxx1/xxx2/xxx3/index

is ‘index’ in case1 a directory or a page?is it a directory in case2 or a page? and how the following links will look like as absolute links in both cases 1 and 2

index.html — ?

./index.html — ?

../index.html — ?

/index.html — ?

I am not sure if it is an easy question for some of you but for me it is confusing?

Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:47:42+00:00Added an answer on May 11, 2026 at 5:47 am

    Direct answer to your example

    In case 1, index is a ‘directory component’ of the URL, while in case 2 index is a ‘file component’ of the URL. This is independent of whether it actually is a regular file or directory on the web server — see the explanation below. I’d call both a ‘page’ if an HTML page is served by the server on those URLs.

    Case 1: (Links from http://www.example.com/xxx1/xxx2/xxx3/index/)

    1. index.html -> http://www.example.com/xxx1/xxx2/xxx3/index/index.html
    2. ./index.html -> http://www.example.com/xxx1/xxx2/xxx3/index/index.html
    3. ../index.html -> http://www.example.com/xxx1/xxx2/xxx3/index.html
    4. /index.html -> http://www.example.com/index.html

    Case 2: (Links from http://www.example.com/xxx1/xxx2/xxx3/index)

    1. index.html -> http://www.example.com/xxx1/xxx2/xxx3/index.html
    2. ./index.html -> http://www.example.com/xxx1/xxx2/xxx3/index.html
    3. ../index.html -> http://www.example.com/xxx1/xxx2/index.html
    4. /index.html -> http://www.example.com/index.html

    So the only one that stays the same is the absolute links – 4.

    Explanation

    Links are relative to the URL the browser is at, which may not be the URL you originally entered (for example on an HTTP redirect). Most web browsers will update the URL bar with the current address once you follow a link or are redirected, so unless you just edited that, the address you see there is the one that counts.

    URLs ending with a slash are considered to refer to directories (implied by RFC2396 for URI syntax, though it does not actually call them that way), else they are considered to refer to files within directories.

    –Side note: This will not necessarily correspond to the filesystem path (if there is one) type used by the web server to serve the file. Most web servers, when asked requested a URL mapping to a directory on their filesystem, will either serve a file within the directory with some set name (often index.html, but the selection can usually be configured), or an HTML directory listing generated by the server (or an access error if that was disabled). The same will usually be served when a ‘file URL’ for the similiar path without a trailing slash is requested, in which case the ‘file URL’ actually maps to a directory filesystem path.—

    This can lead to inconsistencies such as the above example, where the ‘file URL’ http://www.example.com/xxx1/xxx2/xxx3/index is probably equivalent to the ‘directory URL’ http://www.example.com/xxx1/xxx2/xxx3/index/, but relative links may refer to different paths from those two URLs, and one may work and the other may be broken.

    For that reason, when a linking to a directory, it is recommended to always use the ‘directory URL’ (with the terminating slash) and not the equivalent ‘file URL’ – e.g. link to http://www.ietf.org/meetings/ and not http://www.ietf.org/meetings even if both would serve the same page. Many web servers are in fact configured to redirect clients requesting the latter to the former using a an HTTP 301 redirect response. You can see this if you enter the latter in your browser’s URL bar – the URL bar will change to the former once it gets that response.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 169k
  • Answers 169k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is more secure to use Request.Form. This will prevent… May 12, 2026 at 1:55 pm
  • Editorial Team
    Editorial Team added an answer strncpy() is not intended to be used as a safer… May 12, 2026 at 1:55 pm
  • Editorial Team
    Editorial Team added an answer If not all orders have an associated managed_order then you… May 12, 2026 at 1:55 pm

Related Questions

While I have been playing with Python for a few months now (just a
Does anyone have a suggestion for where to find archives or collections of everyday
I am an experienced C++ programmer with average Python skills. The reasons I studied
I am trying to find a better way to integrate IRB with my normal

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.