Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Feb 2018
    Location
    United Kingdom
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ignore/Hide YYYYMMDD from folder names in urls

    Hi. On my website, I have a flat file downloads section. I've make it in such a way so it looks at what "YYYYMMDD" numbers are at the front of folder names for each download in the /files/ subdirectory. This orders them from newest down to the oldest on my auto PHP menu on the downloads homepage.

    This works great, however if I want to update something, the link with the previous YYYYMMDD in the folder name will be dead.

    In order for me to get rid of this one issue, I need to use htaccess or something to make my website ignore the YYYYMMDD numbers at the front of folder names, look at what's afterwards, to direct the person to the right place. Also completely hiding the YYYYMMDD numbers entirely, even though the numbers actually are there, if possible would be great.

    My folder names for each download are:

    /YYYYMMDD-example-download/

    I would like them to be:

    /example-download/

    despite the YYYYMMDD numbers still actually being there.. And if someone or a link does write the numbers in the url, they'll be removed.

    I asked about this on StackOverFlow on the 13th, as well as my own hosting provider's communuty forum.. However as you'll see on my StackOverFlow post, it's quite dead right now, and my everyone from
    my hosting provider's community forum is pretty clueless regarding this. (Been at it trying to work this out for a year)

    If the PHP code I use is of any help in helping me, here's the code:

    PHP Code:
    <?php
    foreach(array_reverse(glob('files/*'GLOB_ONLYDIR)) as $dir) {
        
    $dir str_replace('files/'''$dir);
    ?>

       <div class="download-menu-item">
            <a href="files/<?=$dir?>">
                <img class="download-menu-image" src="files/<?=$dir?>/images/main/thumbs/image-small-thumb.jpg"/>
                <span class="download-menu-title">
                    <?php include("files/$dir/includes/title.php"); ?>
                </span>
            </a>
        </div>

    <?php
    }
    ?>
    Whatever solution I get will be shown on my StackOverFlow and my post on my hosting provider's forum with credit to here.

    P.s admins:
    I have messed up my settings on here on the forum, setting it default to the mobile theme (which therefore kicks me out of settings), and the search keeps saying I've not verified I'm human. So I apologise if what I am asking is a duplicate of some other answered post here.

    Thanks, Jase

  2. #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    4,181
    Thanks
    3
    Thanked 535 Times in 522 Posts
    The URL must specify which file to download. If you want a generic link to cause the latest/only version of any file to be downloaded, you will need to dynamically do this using a .php script to perform the download. The .php download script would get the generic example-download value from the url and use whatever business logic you have that determines which file to actually read and output back to the browser.

    If you want the ability to download any past/present version of a file, the url will need some information in it to identify which of the available files is being requested. This information doesn't need to be the YYYYMMDD date. You could for example just use the example-download for the latest/current version. example-download-1 for the next oldest previous version, example-download-2 for the 2nd oldest version, ... The .php download script would determine the correct path to actually read the file from and output it back to the browser.
    Last edited by CFMaBiSmAd; Feb 26th, 2018 at 10:03 PM.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

  3. #3
    New Coder
    Join Date
    Feb 2018
    Location
    United Kingdom
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry if this is a repeat comment, wrote something but it just vanished when I clicked post..

    This isn't regarding downloading of the actual files I have for download. It is regarding the download pages with the information and pictures showing about the download.

    The folder names with YYYYMMDD I've mentioned about aren't of the downloads themselves. They're specified in the /download subfolder of those folders. They do not have any relation to what the url is at all, and actually already download whatever archive, regardless of the name, is in the download directory.. Or it will go to a specified external link if I change the index file to do so.

    Sorry for the confusion

  4. #4
    New Coder
    Join Date
    Feb 2018
    Location
    United Kingdom
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Right, I've worked out how to redirect links with YYYYMMDD numbers along with the first dash so it looks at the name following. However that's only redirecting, so it's not hiding or ignoring the numbers of the actual folder url.

    Code:
    RewriteRule ^2014/02/20/events-2014/$ /2014/03/02/events-2014/ [L,R=301]
    This takes away my need to even do anything with my PHP menu script.

    But I still need to hide the numbers in the actual url.

  5. #5
    New Coder
    Join Date
    Feb 2018
    Location
    United Kingdom
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry.. Meant to put in this line...

    Code:
    RewriteRule ^[0-9]+-(.+?)/?$ $1 [L,R=301]
    That above one was me trying to find a way to redirect to whatever the new url is with the new numbers. But that's not exactly what I meant. So apologies that was on my thumb.

  6. #6
    New Coder
    Join Date
    Mar 2018
    Posts
    16
    Thanks
    0
    Thanked 1 Time in 1 Post
    I think you would have to change the code how your files are uploaded or stored in database.

  7. #7
    New Coder
    Join Date
    Feb 2018
    Location
    United Kingdom
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Also asked on Web Developer forum.. Where learnt I will need to make use of SQL to hide that from the url. So if I can just make use of redirecting the wrong to the correct, then I'm not that bothered with hiding the numbers.

    So I would want something a mixture of the htaccess code I accidentally posted and the one I posted after.

    The one I posted after redirects "yyyymmdd-title-here" to "title-here", though if I can have it work like so it redirects as "********-title-here", where the stars mean it ignores the numbers and so it'll automatically redirect to whatever is the right page with the right numbers.

    As was said last on my Web Dev thread, it looks like I will have to make use of htaccess rewrite match for that. Though right now I am just clueless how I actually do it.

    Unless someone happens to give me a simplified explanation of how to do it, I'll update this along with my threads in the other places whenever I do eventually work it out.

  8. #8
    New Coder
    Join Date
    Feb 2018
    Location
    United Kingdom
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, just an update to state I solved this issue by actually editing my PHP menu script to use the contents of in a file for each page to order by in the menu, instead of using the folder names. By doing this, that's taken away the need for having numbers in the folder names at all, so I can change the numbers that now are in a json file all I like without it ever touching the url, so no complicated htaccess tricks needed.

    Here's the post on Web Developer where I got help regarding that. Also I used that thread to go many steps further with other ways I can make use of that script for such as filtering the array to only results with values in the json using what is the current page title as the key, which allows me to make archives/categories/tags filtered menu pages etc.

    Sorry for a bit of a delay coming back here to state what my found solution was from when I got that solution on that thread. But anyway, hope this helps, and thanks anyway for the help here despite that I obviously was trying to go the completely wrong way about it when I could make such a simple change to my php menu.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •