SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2008
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Zend rewrite: Check if controller exists...

    Im absolutely horrible when it comes to simple rewrites, so this one is out of the question for me...

    I want the same as:

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
    RewriteCond %{REQUEST_FILENAME} -d [NC]
    RewriteRule .* - [L]
    RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]
    This would, unless directory exists, take /test to page=test. Is it possible to see if a controller exists within Zend, and if not rewrite?

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2008
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heres a bit more information:

    Zend current rewrite information:
    Code:
    SetEnv APPLICATION_ENV development
    
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    My servers document root is C:/xampp/htdocs/wfbl/public/.

    What I want to accomplish is leave the current rewrite working, as well as check c:/xampp/htdocs/wfbl/application/views/scripts to see if the requsted directory exists (ex. url.com/test, if directory test exists in scripts folder, then allow the current rewrite to do its work, if not then rewrite to index.php?page=test)

    If you guys need any more information let me know, Im absolutely clueless with rewrite and Im getting desperate for an answer, I need this working to continue on with this project.

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Kyle,

    This seems rather convoluted but, for your "explanation,"
    ex. url.com/test, if directory test exists in scripts folder, then allow the current rewrite to do its work, if not then rewrite to index.php?page=test
    you need to put the following pseudocode immediately after the RewriteEngine on statement:

    If test/%{REQUEST_URI} -f OR
    If test/%{REQUEST_URI} -d
    RewriteRule ... (redirect to index.php with the query string)

    You may have to add physical path information before test because the file and directory checks are designed to work with {REQUEST_FILENAME}.

    Other mod_rewrite code.

    That's the best I can do with your "specification."
    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2008
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Kyle,

    This seems rather convoluted but, for your "explanation,"
    ex. url.com/test, if directory test exists in scripts folder, then allow the current rewrite to do its work, if not then rewrite to index.php?page=test
    you need to put the following pseudocode immediately after the RewriteEngine on statement:

    If test/%{REQUEST_URI} -f OR
    If test/%{REQUEST_URI} -d
    RewriteRule ... (redirect to index.php with the query string)

    You may have to add physical path information before test because the file and directory checks are designed to work with {REQUEST_FILENAME}.

    Other mod_rewrite code.

    That's the best I can do with your "specification."
    Regards,

    DK
    Im sorry, /test being the variable. so if /test doesnt exist, rewrite to index.php?page=test, or $1 in rewrite terms.

  5. #5
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kyle W View Post
    Im absolutely horrible when it comes to simple rewrites, so this one is out of the question for me...

    I want the same as:

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
    RewriteCond %{REQUEST_FILENAME} -d [NC]
    RewriteRule .* - [L]
    RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]
    This would, unless directory exists, take /test to page=test. Is it possible to see if a controller exists within Zend, and if not rewrite?
    This really is a job best served script-side. I haven't dealt with Zend but in my own framework I send all requests to your router so index.php?url=/blah/blah/ and then let PHP handle it, otherwise you won't have a nice way to degrade gracefully if the page controller doesn't exist

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Hi Dean!

    Welcome back! You go missing for long periods but your help is always welcome.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Hi Dean!

    Welcome back! You go missing for long periods but your help is always welcome.

    Regards,

    DK
    I'm going to try to get back into things ! Been busy with university and such. I've forgotten so much

  8. #8
    SitePoint Zealot
    Join Date
    Nov 2008
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'd figure there'd be some documentation on this somewhere on this, as it's a very common thing to do, but I've come up empty handed.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •