0

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.

13
  • Does you page load properly when you open: http://username.domainname.com/? Commented Feb 11, 2014 at 6:27
  • yes, it works with id only. Commented Feb 11, 2014 at 6:41
  • But there is no id in http://username.domainname.com/? Commented Feb 11, 2014 at 6:42
  • sorry "userid" --> username.domainname.com/userid, works fine Commented Feb 11, 2014 at 6:45
  • And i need username.domainname.com Commented Feb 11, 2014 at 6:45

2 Answers 2

2

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 }
Sign up to request clarification or add additional context in comments.

Comments

1

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]

17 Comments

That is as per your requirement
And username.domainname.com/userid returns "404 not found"
Did URL become username.domainname.com or not?
What do you mean by home page? URL changed to username.domainname.com right?
no, it shows the "domainname.com/index.php" with the url "username.domainname.com"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.