RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,QSA]
To rewrite all requests that do not map to physical files OR that map to .pdf
files in the /uploads
directory to index.php
then you can basically just add an additional OR
'd condition to the above rule.
For example:
RewriteCond %{REQUEST_URI} ^/uploads/[^/]+\.pdf$ [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
So, the above states that any request of the form /uploads/<file>.pdf
(regardless of whether that .pdf
file exists or not) OR that does not map to a physical is rewritten to index.php
.
If you wish to rewrite everything in the /uploads
directory through index.php
then simply change the regex from ^/uploads/[^/]+\.pdf$
to ^/uploads/
.
I also simplified (and made more efficient) the regex in the RewriteRule
directive (since you don't need to match and capture everything) and the QSA
flag was redundant here.
UPDATE:
How is it possible with files, which are in a subfolder of the uploads folder?
You can tweak the regex in the preceding condition (RewriteCond
directive). For example...
A specific subfolder of the uploads folder:
RewriteCond %{REQUEST_URI} ^/uploads/subfolder/[^/]+\.pdf$ [OR]
:
Any subfolder of the uploads folder:
RewriteCond %{REQUEST_URI} ^/uploads/[^/]+/[^/]+\.pdf$ [OR]
:
Any .pdf
file under the /uploads
folder (including any subfolder):
RewriteCond %{REQUEST_URI} ^/uploads/.+\.pdf$ [OR]
:
See the following question for details on regular expressions (regex):
Reference - What does this regex mean?