apache.htaccessmod-rewriteurl-rewritingfriendly-url

.htaccess trying to create Clean URLs mod_rewrite


I have read prior SO questions and read tutorials and I do not understand mod_rewrite fully so I am posting here

Options +FollowSymLinks
RewriteEngine On

#Using THE_REQUEST for catching references and using them later on.
RewriteCond %{THE_REQUEST} \s/(content)/index\.php\?var=(.*?)\s [NC]
RewriteRule ^ /%1/featured/%2? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(content)/featured/(.*?)/?$ $1/index.php?var=$2 [QSA,NC,L]

RewriteRule ^profile/([0-9]+)/ /profile.php?userid=$3 [NC, L] 

I would like to take www. domain.com / profile.php?userid=2343 and rewrite the URL to a clean URL which is www.domain . com/profile/2343/

I have tried a number of variations.. the .htaccess code described above does not work.

Help please?


Solution

  • With your shown attempts, samples. Please make sure to clear your browser cache before testing your URLs.

    Options +FollowSymLinks
    RewriteEngine On
    
    #### 1st set of rules.... ####
    #Using THE_REQUEST for catching references and using them later on.
    RewriteCond %{THE_REQUEST} \s/(content)/index\.php\?var=(.*?)\s [NC]
    RewriteRule ^ /%1/featured/%2? [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(content)/featured/(.*?)/?$ $1/index.php?var=$2 [QSA,NC,L]
    
    
    #### 2nd set of rules.... ####
    #Using THE_REQUEST for catching references and using them later on.
    RewriteCond %{THE_REQUEST} \s/(profile)\.php\?userid=(.*?)\s [NC]
    RewriteRule ^ /%1%2? [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(profile)/(.*?)/?$ $1.php?userid=$2 [QSA,NC,L]