1

In an application I want all users to start at index.php. So I want to redirect all direct URLs to other pages to this file.

When I use the following syntax, only the non-existing files are rewritten, but I want to redirect the existing URLs too.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
1
  • 1
    Remove the RewriteCond ? Commented Dec 8, 2017 at 10:36

1 Answer 1

3

RewriteCond %{REQUEST_FILENAME} !-f means: if this file does not exist, apply the RewriteRule.

RewriteCond %{REQUEST_FILENAME} !-d means: if this directory does not exist, apply the RewriteRule.

Use:

RewriteEngine on
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]

EDIT:

If you want to redirect only when the URL does not start with /index.php yet, use this extra condition:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ /index.php/?path=$1 [NC,L,QSA]
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. This works fine but is it possible to let it work once? so as the entry is index.php than all other url's via de menu will work. I just want all users to force a start at index.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.