Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.php Subject: Re: Fast PHP way to find a file given the leftmost characters of the file name Date: Sat, 5 Dec 2015 19:37:01 +0100 Lines: 66 Message-ID: <56632ECD.8050106@arnowelzel.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net 6bg9egvJhTRrQAYX/g+V5APlc5ynOnm5lpV+tOH2UpE1djb1VP Cancel-Lock: sha1:Frww0jj6bd374cpJuT/vMVLgwR0= In-Reply-To: Xref: csiph.com comp.lang.php:15911 James Harris schrieb am 2015-12-05 um 18:39: [...] > The URL could include the full name (without an extension) or just a > short prefix. For example, if the file names were > > 1001-this-is-a-file.ext1 > 1002-this-is-too.ext2 > 1003-so-is-this.ext1 > > the first of those files could be accessed by either of these URLs: > > http://site.com/dir/1001-this-is-a-file > http://site.com/dir/1001 > > As you can see, the second name is the short form of the first. > > The requests would be directed to a PHP script by URL rewriting. Either > of the URLs could be used to find the same file. Use a database where you store the file names (for example using a kind of maintance script which regularly scans the directory and updates a database table with the current list of files). Otherwise you would have to scan the directory with every request to get the existing file names as a list and find out, which one matches - and this would not be very efficient. [...] > I guess something like this approach to URL shortening is fairly common > for SEO reasons. Maybe there is a standard solution...? Nope. WordPress for example does this "auto completion" as well - but the URLs in WordPress are already only in the database and don't even exist as files. Many other CMSes handle this in a similar way. So for example: When you access you will get redirected to the real URL But this is not done to provide and kind of SEO - it's just for convenience. The opposite is true: Using descriptive URLs is better since the URLs are then also part of the search. Also see: What really hits search engine results is changing old URLs without forwarding to the new ones. is still true. -- Arno Welzel http://arnowelzel.de http://de-rec-fahrrad.de http://fahrradzukunft.de