1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Get current directory name in htaccess and prevent redirection

Discussion in 'Apache' started by omidgfx, Oct 23, 2018.

  1. #3
    I have this .htaccess file:
    
    Options +FollowSymLinks
    DirectorySlash On
    RewriteEngine On
    
    # Remove trailing slash for non directories
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^(.*)/$ /mydir%1/$1 [R,L=303]
    
    # Make direct files accessible
    RewriteCond %{REQUEST_FILENAME} !-f
    
    RewriteCond %{REQUEST_URI} !^base.php.*$
    RewriteRule ^([^\n]+)|(.*)$ base.php?___ROUTE=$1 [QSA,END]
    
    Code (markup):
    Which having following redirection behaviors:

    1. ✔️ d.com/mydir → d.com/mydir/
    2. ✔️ d.com/mydir/nothing → run
    3. ✔️ d.com/mydir/nothing/ → d.com/mydir/nothing
    4. ❌ d.com/mydir/exist_dir → d.com/mydir/exist_dir/?___ROUTE=exist_dir
    5. ❌ d.com/mydir/exist_dir/ → run
    6. ✔️ d.com/mydir/exist_file.css → run
    7. ✔️ d.com/mydir/exist_file.css/ → d.com/mydir/exist_file.css
    By run I mean It respond file contents or execute base.php?___ROUTE=$1

    Now I have a problem and a question

    Problem:

    I don't know how to fix redirection number 4.

    Number 5 should redirect to d.com/mydir/exist_dir.

    And number 4 should execute base.php?___ROUTE=$1 instead of redirection



    Question:

    How can I use current directory name in .htaccess instead of writing it's name in each project?

    I mean /mydir in RewriteRule ^(.*)/$ /mydir%1/$1 [R,L=303]
     
    omidgfx, Oct 23, 2018 IP