The setup
I have some zip archives on my server. The links to those files are peppered about various blogs, YouTube channels, and so on.
I'm moving the files to Google Drive, and since I want to avoid changing the links which are all over the internet, I was thinking of doing automatic redirection to the new Google Drive links.
I've setup my .htaccess like this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*/)?([^/]+\.zip)$ /mydir/myscript.php?dir=$1&file=$2 [L,QSA]
where myscript.php
is parsing the directory name and filename, and passing them on to Google Drive API. The API then returns the download link for the requested file, and redirects the user to it, thereby initiating the download.
The problem
This is working fine, as long as the file actually exists on my server. - After lookin further into this, it seems that this is incorrect, as commented by Cbroe
Once I delete the file, I'm getting 403 Forbidden
.
How can I get my .htaccess to work as I want it to? I want it to redirect the requests to myscript.php, which contains the logic.
EDIT As requested in the comments, I'm providing additional details.
The directory setup is like this:
site root
dir1
dir2
files1 <=== this one has the archives
files2 <=== this one has the archives
files3 <=== this one has the archives
mydir <=== this one handles Google Drive logic
Contents of files1-3
:
files1
.htaccess
archive_1.zip
archive_2.zip
...
archive_n.zip
index.php
EDIT 2 Furhter experiments have shown me that the problem shows up if the file name has spaces.
For example:
https://example.com/files1/archive_1.zip <=== works
https://example.com/files1/archive 1.zip <=== doesn't work