Search code examples
apache.htaccesshttp-redirecthttp-status-code-301

htaccess redirect stuck in loop


In my tool that I wrote, I want only avible index.php file which is in the 'Public' subfolder, my root directory structure (of my application) is following

uapi(root)
   /Application
   /Config
   /Public
       Index.php
   /Storage
   .htaccess

And I want all folders except Public to be redirected to /Public/Index.php, and it cant be domain based because this tool will be available to download and install on the users server.

Here is the .htaccess, but instead of redirecting it normally opens the directory

Redirect 301 /Storage/ http://localhost:800/web/uapi/Public/
Redirect 301 /Application/ http://localhost:800/web/uapi/Public/
Redirect 301 /Config/ http://localhost:800/web/uapi/Public/

Solution

  • Redirect directives only work with absolute pathnames. So if you are using them your .htaccess file should be in the root of the webserver and there should be full pathnames (/web/uapi/Storage, for example). In my opinion it is better to achieve the same using mod_rewrite.

    RewriteEngine On
    RewriteRule ^(?:Storage|Application|Config)/$ Public [L]