HDFilmMaker2112 Posted June 18, 2012 Share Posted June 18, 2012 How would I got about using mod_rewrite to rewrite: www.domain.com/index.php?home to www.domain.com/home but also have www.domain.com/index.php?profile=user_name to www.domain.com/username Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted June 18, 2012 Author Share Posted June 18, 2012 How would I got about using mod_rewrite to rewrite: www.domain.com/index.php?home to www.domain.com/home but also have www.domain.com/index.php?profile=user_name to www.domain.com/username I guess I should be clear about this part: www.domain.com/index.php?profile=user_name to www.domain.com/username That should be a variable $user_name, would be rewritten to the same value of the variable. So: www.domain.com/index.php?profile=John would be rewritten to www.domain.com/John Could I just order them in order of importance, like this: RewriteRule ^/?([a-zA-Z0-9-]+)(?:/(.*))?$ index.php?$1 RewriteRule ^/?([a-zA-Z0-9-]+)(?:/(.*))?$ index.php?profile=$1 So things like /home would be caught first and see that value is in the php file. And when something isn't caught it would go to the next rewrite rule. I guess one issue is I have an else statement in the php file, so it will also return that, as opposed to going to the rewrite rule. Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted June 19, 2012 Author Share Posted June 19, 2012 RewriteRule ^([A-Za-z0-9_]+)/?([A-Za-z0-9_]+)?/?$ /index.php?p=$1&edit=$2 Would the above match anything between a-Z and 0-9 with an optional / and an optional second "folder" with an optional /. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.