1

In my current ZF project, I've two public access points (files) ready to handle & process coming requests, that's: index.php & admin.php

I need all URLs containing '/admin' to be routed to admin.php while any other URLs doesn't contain '/admin' to be routed to index.php

Knowing that default ZF htaccess contains the following rules:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

How this can be implemented?

4
  • 3
    I don't understand why you have to do such thing. You can simply have one entry point and, based on the url, add a new route that redirect to the right controller (or wharever you want). Commented Oct 26, 2011 at 18:25
  • This is a big project that contains too many modules for each Backend & Frontend, 'admin' can't be neither a single module nor scattered controllers inside every module. Both Backend & Fronend should be completely separated so every end can get benefit of the full modular features. And that's why I see that two access points are required. If you understand my circumstances & know a better solution, please don't hesitate to advice. Commented Oct 26, 2011 at 18:30
  • Well, if I understand well your needs, this can be still done using routes and a single entry point. Infact, you are always redirecting the user based on the url and so I see no difference in using routes or two entry points. Commented Oct 26, 2011 at 18:36
  • 1
    Something like this: wdvl.com/Authoring/PHP/Zend_Routes/Jason_Gilmore04282010.html Commented Oct 26, 2011 at 18:48

1 Answer 1

2

I want to start by saying that I full heartedly agree with AurelioDeRosa. I do believe that routes will be a better choice. However that is your choice not mine and this .htaccess code should do the trick you want.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*(admin).*$ admin.php [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Note however that this script will catch anything that contains admin so it might break your frontend. for example, if you want to list all your users with administrative rights the url yoursite.com/users/listby/admin/ will redirect the request to admin.php, and so will urls like /administrator/ or /adminininini

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, these rules not working! It is still routing all requests to index.php
Strange. For some reason the code didn't work with the slashes. I'm no expert in rewrite RegExp do I can't explain why, but I've corrected and tested the code and updated my answer above.

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.