Forum Moderators: phranque
The reason is that i want to log requests to certain .doc and .pdf files. I've saved their contents in a database and what i want to do now is this:
if a visitor request, for example, file_this_and_that.doc, htaccess should (silently) redirect to download.php - this will look for that name in the database, output the contents and log te request.
But: the visitor (or search engine) should not really be redirected to download.php. In the locationbar it should still say file_this_and_that.doc
(btw, everything else (download.php) already works. It's just that i need an alternative for the 301
An external redirect sends an HTTP redirect response to the client (e.g. browser or search robot), telling it to re-request the desired content using a new URL supplied within that redirect response. Thus, the client becomes aware of the new URL, and in the case of a browser, the new URL is displayed to the user. The receipt of this redirect response by the client ends the current HTTP transaction. If the client opts to re-request the desired content using the new URL, this request defines a new HTTP transaction.
By contrast, an internal rewrite changes only the filename (or the path to a script) that is associated with the originally-requested URL. This is done entirely within the context of the original HTTP request. As such, it is 'silent,' since the client --and therefore, the user-- are unaware that the request has been rewritten inside the server. This can only be used within the server; It is impossible to do an internal rewrite to another domain, since that is a contradiction in terms (**See note).
Apache mod_rewrite supports both functions, as well as several others. The only difference in coding an external redirect versus an internal rewrite is in the syntax:
External Redirect:
RewriteRule ^file_this_and_that\.doc$ http://www.example.com/download.php [R=301,L]
RewriteRule ^file_this_and_that\.doc$ /download.php [L]
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
** Note: See RewriteRule's [P] flag for a possible solution using a proxy request.
Jim