www.webdeveloper.com
Results 1 to 3 of 3

Thread: mod_rewrite - how to strip .php off URLs under certain conditions

  1. #1
    Join Date
    Dec 2002
    Posts
    150

    mod_rewrite - how to strip .php off URLs under certain conditions

    I'm using the following in .htaccess to strip ".php" off requested URLs:

    RewriteCond %{THE_REQUEST} ^GET\ /.+\.php(\?[^\ ]*)?\ HTTP/
    RewriteRule ^(.+)\.php$ http://www.mydomain.org/$1/? [R=301,L]

    However, the admin for this site DOES need the .php displayed - e.g.:

    http://www.mydomain.org/admin/editSomething.php

    How can I alter my above mod_rewrite rule so that it does NOT activate if the request points at the "admin" directory?

    Something to do with:
    !^admin
    but I'm not sure how to work that into the above.

    Thanks!

    - Bob

  2. #2
    Join Date
    Dec 2002
    Posts
    150
    Anybody?

    Or - can someone recommend a better forum for mod_rewrite issues? I realize there isn't a lot of traffic here - perhaps I need to post this question somewhere that there is. Just not sure where that is

    - Bob

  3. #3
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    You can add a precursory no-rewrite rule for that directory. It would be something like this ...

    Code:
    # rewrite free-directories ...
    RewriteRule ^admin/ - [L]
    RewriteRule ^images/ - [L]
    RewriteRule ^and_so_on/ - [L]
    
    # all other directories get redirected as follows ...
    RewriteCond %{THE_REQUEST} ^GET\ /.+\.php(\?[^\ ]*)?\ HTTP/
    RewriteRule ^(.+)\.php$ http://www.mydomain.org/$1/? [R=301,L]
    Make sense?
    Jon Wire

    thepointless.com | rounded corner generator

    I agree with Apple. Flash is just terrible.

    Use CODE tags!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles