skip to Main Content

I’m trying to redirect all site traffic to my front controller, but I’ve been having trouble with it getting my site to redirect when the file already exists. For instance: www.example.com/IDontExist/ doesn’t exist and sends me to the controller, but www.example.com/maintence/ exist and therefore skips my controller entirely. Not the intention.

I’ve tried a couple of things in .htaccess files, and I need to use them because I have to upload it to a Godaddy Shared Linux Server, and don’t have much access to higher class configs.

This is my current .htaccess file:

RewriteEngine On
DirectorySlash Off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /index.php [NC,L,QSA]
</IfModule>

I need to send people going to www.example.com/maintenance/ and all other urls to the front controller to get the page processed before sending it off to the client. Right now it’s finding the file and loading that up before going to the front controller.

Edit: Forgot removing RewriteCond commands for some reason result in a 500 error.

2

Answers


  1. Chosen as BEST ANSWER

    It was a redirect loop. Removing the conditions and then adding the following one would fixed it.

    RewriteCond %{REQUEST_URI} !/index.php
    

  2. Remove your file and directories excludes, after that

    RewriteEngine On
    RewriteRule ^([^?]*)$ /index.php [NC,L,QSA]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search