简体   繁体   中英

remove subfolder name in url using htaccess

i have an site and using the htaccess code for redirections, in that, i have url like "http://username.domainname.com/userid" and want to remove the part "userid", so that, the url will look like "http://username.domainname.com/" .

i use the following code to get "http://username.domainname.com/userid" :

RewriteEngine on
RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+)$ /user_detail.php?cId=$1 [NC,L]

thanks in advance to help me.

i wrote a set of code in php page, which is finely working. in index page, include the following code :

$cId=0;
 $url=$_SERVER['HTTP_HOST'];
 $a= explode(".",$url);
 $objComp = new mysql_profile();
    $arrOrg= $objComp->select_admin_profileorgs(0);
    if($a[1]!='bgrow')
    {
      if(count($arrOrg) > 0)
    {  
        for($i=0;$i<count($arrOrg);$i++){ 
         $cUrl = $arrOrg[$i]['cUrl'];
         if((strtolower($cUrl) == $a[0]) || (strtolower($cUrl) == $a[1])) {  
            include($PATH."domain.com/user_detail.php");
         }
    }   
    } 
    }
    else { // inderpage content }

Try this rule for redirection:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.domainname\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^\w+/?$ / [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^([^.]+)\.domainname\.com$ [NC]
RewriteRule ^$ /user_detail.php?cName=%1 [QSA,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM