: .htaccess (AddIcon AddDescription AddAlt) not working on directory .URL files I have recently learned how to use my .htaccess file and a script to rewrite .URL shortcuts into functional links
I have recently learned how to use my .htaccess file and a script to rewrite .URL shortcuts into functional links in a directory listing:
Make .URL shortcuts into functional links within a Directory Listing
That solution is working well ... but my other .htaccess calls to modify the .URL items aren't working (unlike all the other file types):
AddIcon SoSaysSunny.com/icos/url.ico .URL
AddDescription "<I>(web link)</I>" .URL
AddAlt "URL" *.URL
Did the rewriting process change the file extension?
Is there some other way to refer to these files?
Once I get that problem fixed, I have another: I begin the filenames of links to web stores with a "$". How can I specify the files with this naming scheme?
Here's what doesn't work (even with other file types):
AddIcon SoSaysSunny.com/icos/cart.ico $*.URL
AddDescription "<I>(web store link)</I>" $*.URL
I know it seems like a lot of work to use directory listing but it's crucial to my website organization (to avoid constantly having to update HTML index files).
Directory of Problem
I really appreciate your help.
More posts by @Fox8124981
1 Comments
Sorted by latest first Latest Oldest Best
but my other .htaccess calls to modify the .URL items aren't working (unlike all the other file types)
Ah, yes, the "problem" is actually with the mod_rewrite code that sends requests for .URL files to your PHP script (that parses the file to get the URL to redirect to). This just needs a minor change: the NS flag is required on the RewriteRule directive.
The problem stems from the fact that when Apache constructs a directory listing it issues an internal subrequest for each file that is listed. The mod_rewrite code is rewriting this internal subrequest, which it doesn't need to, and preventing the AddIcon directive from matching (since the .url request is rewritten to a .php script). (It only needs to rewrite direct requests from the user.) Based on my earlier answer to your question, you probably have something like the following in your .htaccess file:
# Rewrite requests for ".url" files to our PHP script
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ..url$ process-url-shortcut.php [NC,E=URL_FILE:%{REQUEST_FILENAME},L]
You just need to add the NS (nosubreq) flag to the RewriteRule in order to prevent the directive being processed for subrequests (ie. so it's only processed for non-subrequests). For example:
RewriteRule ..url$ process-url-shortcut.php [NS,NC,E=URL_FILE:%{REQUEST_FILENAME},L]
I begin the filenames of links to web stores with a "$". How can I specify the files with this naming scheme?
Ok, this a bit of a weird one. However, this seems to work if you change the wildcard pattern from $*.URL to *$*.URL, ie. append a * to the pattern (as if there were characters before the $ - but there isn't). So, for example:
AddIcon SoSaysSunny.com/icos/cart.ico *$*.URL
AddDescription "<I>(web store link)</I>" $*.URL
The AddDescription directive still seems to work OK with the $*.URL pattern!
SoSaysSunny.com/icos/cart.ico
Another potential problem is that you appear to be using ICO format files for your icons (mime-type: image/x-icon). This is primarily a Microsoft Windows file format, so they aren't going to display (correctly) on all OS/devices. eg. These won't display at all on Android/iOS (iPhone/iPad) if that is a concern. It would be preferable to use PNG (or GIF) files instead.
...to avoid constantly having to update HTML index files
I agree, no-one want's to manually update an index file every time you upload a file. However, the alternative is to have a (PHP) script that generates your directory listing instead of relying on Apache. Whilst this might be more work in the beginning (unless you have a premade script) - this would potentially give you far greater control and a more portable solution.
UPDATE:
... But the *$*.URL modifications still aren't working.
You need to change the order of the directives so that the most specific directives/patterns are first. In other words, you currently have:
AddIcon example.com/icos/url.png .URL
AddDescription "<I>(web link)</I>" .URL
AddIcon example.com/icos/cart.png *$*.URL
AddDescription "<I>(web store link)</I>" $*.URL
AddAlt "URL" *.URL
The directives need to be reversed, so that the most specific (ie. $*.URL) are first:
AddIcon example.com/icos/cart.png *$*.URL
AddDescription "<I>(web store link)</I>" $*.URL
AddIcon example.com/icos/url.png .URL
AddDescription "<I>(web link)</I>" .URL
AddAlt "URL" *.URL
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.