mod_rewrite für Dateien! :-)
Posted: Mon 22. Mar 2004, 00:27
Summary for english - speakers:
The code modifications in this article allow to modify the displayed download path for the web browser, so it will display
PHPWCMS ist eine der besten CMSen weit und breit, einziger Nachteil war für mich bisher, dass Dateien zum Downloaden nicht in der Form
verlinkt waren. Dank dem absolut genialen Mod_rewrite das die Apache-Götter geschrieben haben, ist es möglich diesem Manko Abhilfe zu schaffen, durch erstellen / modifizieren von nur zwei Dateien.
Zunächst mal, wie schaut das ganze dann besser aus?
Wie man sieht, wird die gesamte Information erhalten, und mod_rewrite macht daraus intern (d.h. für den Surfer nicht sichtbar!)
Ok. Jetzt zum Code!
Achja noch kurz auf Voraussetzungen eingehen:
1. PHPWCMS ist in einem toplevel - Verzeichnis installiert (d.h. z.B.
PHPWCMS is installed in a toplevel directory
2. Es wird kein Verzeichnis mit dem Namen downloads unter diesem toplevel Verzeichnis benutzt ... (wenn doch, dann ist es u.U. nach diesem Mod nicht mehr zugänglich)
the directory downloads won't be accessible if exists
Ok. Jetzt wirklich zum Code!
Zunächst die .htaccess
Please customise the lower 404 part, else it'll display my 404.
Save this file as .htaccess to your root directory (where PHPWCMS should be located, see above! If not, it's easy to modify the approach.)
After this you also need to modify the
include/inc_front/content.article.inc.php
Search for fsize (part of a word, NOT whole word!)
look above for the following code-part
Replace with:
Thats it. Upload the modified file and enjoy 
Troubleshooting:
* Is PHPWCMS in the root directory of the domain / subdomain?
(Above has to be modified if not so)
* Your Provider may not support Mod_rewrite on apache ... try with a little .htaccess script like this
This will basically relocate from index.html to index2.html, and the user will be aware of it. if this does not work I think your mod_rewrite is off, or I am too tired already 
* This is only for your web downloads, NOT for the internal downloads after logging in (additional modification needs to be done for this.)
@Oliver hope this finds somehow its way into PHPWCMS (as an option, maybe?)
The code modifications in this article allow to modify the displayed download path for the web browser, so it will display
Code: Select all
for the original filename of the file
meinegeheimenbilder.zip
instead of PHPWCMS standard
download.php?id=80162,28,1
the following link-
downloads/80162,28,1/meinegeheimenbilder.zip
PHPWCMS ist eine der besten CMSen weit und breit, einziger Nachteil war für mich bisher, dass Dateien zum Downloaden nicht in der Form
Code: Select all
meinegeheimenbilder.zip
sondern z.B:
download.php?id=80162,28,1



Zunächst mal, wie schaut das ganze dann besser aus?
Code: Select all
Aus
meinegeheimenbilder.zip
bzw.
download.php?id=80162,28,1
wird
downloads/80162,28,1/meinegeheimenbilder.zip
Code: Select all
download.php?id=80162,28,1

Achja noch kurz auf Voraussetzungen eingehen:
1. PHPWCMS ist in einem toplevel - Verzeichnis installiert (d.h. z.B.
Code: Select all
destiny.lavadots.com
und nicht
destiny.lavadots.com/mein/langer/pfad/phpwcms
2. Es wird kein Verzeichnis mit dem Namen downloads unter diesem toplevel Verzeichnis benutzt ... (wenn doch, dann ist es u.U. nach diesem Mod nicht mehr zugänglich)
the directory downloads won't be accessible if exists
Ok. Jetzt wirklich zum Code!


Zunächst die .htaccess
Code: Select all
RewriteEngine on
#The holy grail code :-) Took me around two hours to figure out.
RewriteRule downloads/([^/]*)/.*$ /download.php?id=$1 [L]
#and now for the custom 404 doc
ErrorDocument 404 http://404.lavadots.com
Save this file as .htaccess to your root directory (where PHPWCMS should be located, see above! If not, it's easy to modify the approach.)
After this you also need to modify the
include/inc_front/content.article.inc.php
Search for fsize (part of a word, NOT whole word!)
look above for the following code-part
Code: Select all
"<a href=\"download.php?id=".$fxb[$key]["size"].",".$fxb[$key]["fid"].",".
$fxb[$key]["uid"]."\" title=\"download file ".
$fxb[$key]["fname"]."\" target=\"_blank\">".
Code: Select all
"<a href=\"downloads/".$fxb[$key]["size"].",".$fxb[$key]["fid"].",".
$fxb[$key]["uid"]."/" . $fxb[$key]["fname"] . "\" title=\"download file ".
$fxb[$key]["fname"]."\" target=\"_blank\">".

Troubleshooting:
* Is PHPWCMS in the root directory of the domain / subdomain?
(Above has to be modified if not so)
* Your Provider may not support Mod_rewrite on apache ... try with a little .htaccess script like this
Code: Select all
RewriteEngine on
RewriteRule index.html index2.html [R,L]

* This is only for your web downloads, NOT for the internal downloads after logging in (additional modification needs to be done for this.)
