Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use apache mod_rewrite and alias at the same time?
    primarykey
    data
    text
    <p>I have a directory outside the webroot that is used for storing images uploaded from a separate admin system. Images are stored in this format:</p> <pre><code>filepath/writable/images/00/00/23/65/filename-236581.jpg </code></pre> <p>(where the webroot is filepath/html)</p> <p>...for example. Here, 236 is the ID of the image in the database, and the file system is broken into numbered directories to stop more than 100 inodes from being used within one directory.</p> <p>I want to be able to access these from the front-end webserver, like this:</p> <pre><code>http://(server)/filename-236581.jpg </code></pre> <p>Where filename is an seo-optimised string, the same as on the name of the actual file.</p> <p>I can get mod-rewrite to rewrite the URL so that it contains the extra numbered directories, and I can get alias to redirect the request to the writable/images directory, but I can't do both at the same time. If I put both the alias and mod_rewrite directives in, it ignores the alias one and the error log complains that it can't find filepath/html/uploaded-images.</p> <p>Here is what I have so far:</p> <pre><code>RewriteRule ^(.*)\/([^\/]*)-([0-9])\.(gif|jpg|jpeg|png)$ /uploaded-images/00/00/00/00/$2-$3.$4 [L,NC] </code></pre> <p>...and so on, all the way up to:</p> <pre><code>RewriteRule ^(.*)\/([^\/]*)-([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])\.(gif|jpg|jpeg|png)$ /uploaded-images/$3$4/$5$6/$7$8/$9$10/$2-$3$4$5$6$7$8$9$10$11$12.$13 [L,NC] alias /uploaded-images "filepath/writable/images" </code></pre> <p>Removing the [L] makes no difference.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload