htaccess rewrite directory patterns

Discussion in 'Server Operation' started by gring, Feb 11, 2011.

  1. gring

    gring Member HowtoForge Supporter

    [solved] htaccess rewrite directory patterns

    Hi, sorry if I post in the wrong forum, this is both about website dev and apache configuration.

    How can I redirect, using a .htaccess file, a "fake" directory url, like

    http://www.example.com/hard_directory/var1/var2/var3.php
    to /hard_directory/script.php?var1=$var1&var2=$var2&var3=$var3

    my .htaccess file, placed in /hard_directory/ contains:

    Code:
    Options +FollowSymlinks
    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^([^/]*)/([^/]*)\.php$ script.php?id_urlrw1=$1&id_urlrw=$2 [L]
    
    It doesn't produce a 404, just a blank page, and script.php is not called.
    I also tried to escape the slash, to remove the RewriteConds, and replace [^/] with .*

    Help :)
     
    Last edited: Feb 12, 2011
  2. gring

    gring Member HowtoForge Supporter

    Ok, I solved it with this .htaccess file:
    Code:
    Options +FollowSymlinks
    RewriteEngine on
    
    RewriteBase /repertoire_hard/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]*)/([^/]*)\.php$ script.php?var1=$1&var2=$2 [L]
    
    RewriteBase /repertoire_hard/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^([^/]*)\.php$ script2.php?var=$1 [L]
    
    When trying to make them work, use [R] to see where your redirects point.
     

Share This Page