• http://www.xyz.com/myfiles/file1

    When I click that link, it shows me file1.txt. So the URL is actually http://www.xyz.com/myfile/file1.txt

    How does WordPress know to grab that particular file? what if I also have file1.jpg at the same location?

    • This topic was modified 6 years, 5 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not a Developing with WordPress topic
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    WP itself does not normally serve files. If a requested file exists, WP is not even involved. It’s possible a special template for post “file1” to retrieve a file and stream out its content. Unusual, but possible. The template would need to know the full file name in order to fetch it, though it could conceivably search for partial matches and simply fetch the first match found.

    In any case, it’s silly for WP to serve files. It’s purpose is to serve content from a DB. Serving files is better handled by the web server itself, not WP.

    Thread Starter theod44

    (@theod44)

    Thank you for your reply. Let me clarify a little bit:

    On a website, there is this page:
    http://www.xyz.com/myfiles

    When I go there, it shows some content, including an icon with this URL:
    http://www.xyz.com/myfiles/file1

    if I click on the icon, it shows file1.txt

    So the URL is not part of a separate post, just some static URL on a page.

    I see your point with WP/server handling files, but how does that apply to this case?

    • This reply was modified 6 years, 5 months ago by theod44.
    Moderator bcworkz

    (@bcworkz)

    Without seeing the applicable code it’s hard to say. There’s possibly a rewrite rule that converts the URL to index.php?page_name=myfiles&file=file1 or similar. I imagine myfiles template code is automatically appending the .txt part to the passed “file1” value, then either streaming the content or simply doing an internal redirect to the file. Either way, the file content is sent to the browser.

    This sort of thing is sometimes done to prevent users from directly accessing the file until they’ve jumped through some hoops like providing personal information. The file location may not be publicly accessible, but PHP can access it.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How does this URL work?’ is closed to new replies.