1

i am creating a website that handle a profile page and i need to get the username from the URL until this point all work fine but i am having a problem with using the .htaccess and i do not know how to fix this error this is my first time to use the .htaccess i am using the WAMP package and the browser give me this error after i add the .htaccess file and it hide the folder that contain it.

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at admin@localhost to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log. this is a part of the profile.php

profile.php

  // updatede for using the GET methode for ge the data nedded from the url 
    if(isset($_GET['u']))
    {
          $username = mysql_real_escape_string($_GET['u']);
          if(ctype_alnum($username))
         {


          //check user exist
             $check = mysql_query("SELECT user_name, first_name FROM user WHERE user_name = '$username' ")or die(mysql_error());
             if (mysql_num_rows($check)==1) 
             {
               $get = mysql_fetch_assoc($check);
               $username = $get['user_name']; 
               $fname = $get['first_name'];
             }
             else
             {
                echo "<h2>User does not Exist!!</h2>";
                exit();  
             }
          }
       }

        echo "$username";
?>      

.htaccess

RewriteEngine On

RewriteRule^([a-zA-Z0-9_-]+)$ profile.php?u=$1



RewriteRule^([a-zA-Z0-9_-]+)/$ profile.php?u=$1
9
  • Did you try adding whitespaces between RewriteRule and your rewrite rules? Commented Mar 17, 2013 at 20:08
  • I'm using my mobile browser so it's hard to tell, but I think your formatting is wrong there should be a space after rewriterule before the ^ Commented Mar 17, 2013 at 20:11
  • yes their is a space between these 2 lines RewriteRule^([a-zA-Z0-9_-]+)$ profile.php?u=$1 RewriteRule^([a-zA-Z0-9_-]+)/$ profile.php?u=$1 Commented Mar 17, 2013 at 20:15
  • @user2172837 That's not what you are being asked; there's a big difference between this: RewriteRule^([a-zA-Z0-9_-]+)$ profile.php?u=$1 and this: RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1 (the last example having a whitespace after RewriteRule). Commented Mar 17, 2013 at 20:17
  • 1
    I did - two times! You need to have a space between RewriteRule and ^([a-zA-Z0-9_-]+)$ profile.php?u=$1 in your .htaccess file. A space - the long button in the bottom of your keyboard. Commented Mar 17, 2013 at 20:27

2 Answers 2

1

Do not save your .htaccess file in UTF8 charcter encoding. save it in ANSI

Sign up to request clarification or add additional context in comments.

9 Comments

why would you do such a thing, i've always used utf-8 without any problem
@Sebas I had experience about it. perhaps some apache servers have problem with it.
mmm so how to solve this is that any tutorial that i use it ?? be cause until now i did not get success with this error
@user2172837, just save it in ANSI mode.hope this solve your problem. you can use windows Notepad and then save as, then select ANSI
@Amir still the same error .. does the place of the file must be in some specific path or no because the folder that hold .htaccess it is hidding and i can not choose it
|
0

Assuming that profile.php has no errors. Try to delete your last line of the .htaccess file. Also add a space between Rewriterule and '^'. Adding whitespace to the regex has nothing do to with this, because of the ctype_alnum() function. This only permits alphabetic characters.

Just copy and pase this to your .htaccess file and (ofcourse) delete the previous lines:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1

1 Comment

i did as you said but the error still the same and the folder still not appearing

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.