I am working on a new site, and it will be based on (so far) Zend Framework.

I need the best approach to make www.example.com/user work to display the 'user'.

However since it may have other items on the site, such as www.example.com/help etc that still needs to goto the 'help' controller.

i would effectively like to say if its one level i.e. example.com/<whatever> that it will be redirected to www.example.com/profile/person/<whatever>

Now the question is - I can work with the Zend Framework's error controller to detect if it is an invalid controller (and block all usernames from being the same as any of the controllers) then display the profile, OR redirect to the profile.

This method would make:

www.example.com/big.nerd

Check -> no big.nerd controller found -> Passes to Error Controller.
Error Controller -> Search for User, if Found, redirect to www.example.com/profile/person/big.nerd .. and if not .. display not found error / etc.

I am absolutely terrible at URL rewriting, so I won't even venture a guess as to how I would do it.

If i've made any sense at all, I am looking for any recommendations on the best approach would be?

Example of Standard Zend Framework .htaccess

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

Thanks in advance for any advice anyone can give me.

    Why not use the typical .htaccess rewrites to push everything to your index.php file and use Zend Framework's Front Router to generate the urls you want. You can set up a typical: module/controller/action and controller/action urls (so /profile/view/username/bpat1434 would execute the view action of the profiler controller and the username request parameter would be populated with bpat1434). Then you could dynamically look at what's in the database for usernames and map them manually.

    Or you could use the error controller like you want, but the .htaccess rewrites are still the same:

    RewriteEngine On
    RewriteBase /
    RewriteCond &#37;{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php [L]

      Excellent suggestion!

      Now, just for my future reference, what is the core difference between the two .htaccess rules?

      From what I get, the original one that I posted is:

      If the filename is a Real File with Size, OR its a symbolic link (-l) or it's a directory.

      From what I can see th eone you are suggesting is if it's NOT a file, and NOT a directory, then place all to index.php (Last Rule)

      I am just not sure what the actual functional difference is (outside of yours not having the NON-CASE)

      Sorry to bother, but hey I gotta get a handle on this stuff sooner or later.

        8 days later

        No real functional difference except that mine looks a little cleaner and is the more standard form you'd find in any other installation.

          Write a Reply...