Page 1 of 1

mod_rewrite für Dateien! :-)

Posted: Mon 22. Mar 2004, 00:27
by destiny
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

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 
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.

:lol: :lol: :lol:

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
Wie man sieht, wird die gesamte Information erhalten, und mod_rewrite macht daraus intern (d.h. für den Surfer nicht sichtbar!)

Code: Select all

download.php?id=80162,28,1 
Ok. Jetzt zum Code! :twisted:

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
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!
:twisted: :twisted:
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
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

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\">".
Replace with:

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\">".
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

Code: Select all

RewriteEngine on 
RewriteRule index.html index2.html [R,L]
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.)

:twisted: @Oliver hope this finds somehow its way into PHPWCMS (as an option, maybe?)

Posted: Mon 22. Mar 2004, 10:05
by Jan212
good idea, good work, thank you for sharing with us...

Update

Posted: Sat 5. Jun 2004, 09:19
by destiny
In the new version, Oliver has moved the content parts includes out of the central content.article.inc.php into several files. As such, the hack had to be modified ... You can download the updated version of the hack here: http://downloads.lavadots.com/cnt7.article.inc.zip. It is basically the same procedure with .htaccess and mod_rewrite, but you need to replace cnt7.article.inc.php in include/inc_front/content with the patched file now instead of editing content.article.inc.php!. (To revert to the old state easily (why would you want to?) you could backup the other file first.