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 Link to comment https://forums.phpfreaks.com/topic/264359-rewrite-to-different-kinds-of-php-conditions/ 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. Link to comment https://forums.phpfreaks.com/topic/264359-rewrite-to-different-kinds-of-php-conditions/#findComment-1354757 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 /. Link to comment https://forums.phpfreaks.com/topic/264359-rewrite-to-different-kinds-of-php-conditions/#findComment-1355052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.