0

I have an application running at https://webapp.ex - An external application downloads hundreds of PDFs from within the application directory (e.g. https://webapp.ex/Modules/sub/directory/study.pdf) - The 'Modules' directory has grown significantly and I would like to separate it by moving the Modules folder to a separate directory outside my application root.

I've done this by creating a separate virtual host and now have https://modules.webapp.ex and can access the files at https://modules.webapp.ex/Modules/sub/directory/study.pdf - However, I will have to update the URLs for over 300 courses on an external application to fetch the PDFs.

I am trying to avoid this by using Apache Mod rewrite with a rule that redirects all requests to https://webapp.ex/Modules/* to the new sub-domain https://modules.webapp.ex/Modules/* - This way, PDFs are still delivered and I can delete the former directory.

After reading through some ServerFault answers, I came up with the following:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^webapp.ex !^/Modules [NC]
RewriteRule ^(.*)$ https://modules.webapp.ex/$1 [L,R=301]

I added the above to my VirtualHost and Apache fails to restart with this error

AH00526: Syntax error on line 77 of /etc/apache2/sites-enabled/acms.conf: RewriteCond: bad flag delimiters Action 'configtest' failed. The Apache error log may have more information.

I've checked the rewrite statement above using this tool and this URL: http://htaccess.mwl.be/ - I'm not sure why Apache is crying. Please help!

Ralph
  • 802
  • 11
  • 25
  • 1
    You could also [avoid mod_rewrite for a simple redirect](https://httpd.apache.org/docs/2.4/rewrite/avoid.html) and can simply use `Redirect "/Modules/" "https://modules.webapp.ex/"` – HBruijn Nov 01 '17 at 14:30
  • Thanks a lot for your help @HBruijn - That worked flawlessly. – Ralph Nov 01 '17 at 23:23

0 Answers0