How to Rewrite URL in htaccess with php?

.htaccess redirect http://www.mypage.com/user/somedude example?

  • .htaccess redirect http://www.mypage.com/user/somedude example? Hello, I have the current .htaccess and I have a few issues: Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule .* - [L] RewriteRule ^(.*)$ http://www.mypage.com/home.php?u=$1/ [L,R=301] The problem is that if you type "www.mypage.com" in the url bar, it redirects you to: http://www.mypage.com/home.php?u=/ instead of http://www.mypage.com/index.php Also, I would like to add the /user/ dir to the url like this: http://www.mypage.com/user/someDude and it redirects you to http://www.mypage.com/home.php?u=someDude Finally, is there a problem if I change the (.*) to only numbers and alphabetic; (#[^a-z0-9]#i) something like that. If you can give the example will be really amazing. Note: the usernames only contain numbers and letters. Thanks, by the way, four days ago I had no idea .htaccess exist. =)

  • Answer:

    "Thanks, by the way, four days ago I had no idea .htaccess exist. =)" ... and, for what I assume, you don't know much about programming the web either. In that case, STAY AWAY FROM .htaccess! Even well experienced programmers have problems with .htaccess. Reset or erase all contents of your .htaccess and start coding, properly, your index.php: THAT is where you should start. You will then use $_GET to grab the query string (the stuff after "?"), and, from there, redirect your user to whatever you want. You could also analyse the $_REQUEST variable to find out if the user has entered "something else".

Bona at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

"Thanks, by the way, four days ago I had no idea .htaccess exist. =)" ... and, for what I assume, you don't know much about programming the web either. In that case, STAY AWAY FROM .htaccess! Even well experienced programmers have problems with .htaccess. Reset or erase all contents of your .htaccess and start coding, properly, your index.php: THAT is where you should start. You will then use $_GET to grab the query string (the stuff after "?"), and, from there, redirect your user to whatever you want. You could also analyse the $_REQUEST variable to find out if the user has entered "something else".

just "JR"

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.