Pain Posted August 1, 2012 Share Posted August 1, 2012 Hi there. I'm have a rewritten url for a social site members and it looks like this: http://theWeb.net/user_nickname However i would like it to look like: http://theWeb.net/member/user_nickname Can i somehow do this with mod rewriting? I've got some code from the .htaccess, your help would be very much appreciated! RewriteBase / RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php RewriteRule ^user_profile-([0-9]+)\.php$ user_profile.php?id=$1 RewriteRule ^user-profile/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ user_profile.php?id=$2 RewriteRule ^([a-zA-Z0-9_-]+)$ user_profile.php?username=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ user_profile.php?username=$1 Quote Link to comment https://forums.phpfreaks.com/topic/266567-mod-rewrite-help/ Share on other sites More sharing options...
requinix Posted August 1, 2012 Share Posted August 1, 2012 RewriteRule ^([a-zA-Z0-9_-]+)$ user_profile.php?username=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ user_profile.php?username=$1 Those are the two you'll want to change, but first RewriteRule ^([a-zA-Z0-9_-]+)/?$ user_profile.php?username=$1 they can be combined into just the one. So modify that to include the directory (take a stab at it) and replace it in. Quote Link to comment https://forums.phpfreaks.com/topic/266567-mod-rewrite-help/#findComment-1366105 Share on other sites More sharing options...
Pain Posted August 2, 2012 Author Share Posted August 2, 2012 Thanks for the answer! This is what i've come up with: RewriteRule ^member/([a-zA-Z0-9_-]+)/?$ user_profile.php?username=$1 Looks like it does work, however i think i must create an actual directory called 'member'? Quote Link to comment https://forums.phpfreaks.com/topic/266567-mod-rewrite-help/#findComment-1366252 Share on other sites More sharing options...
Jessica Posted August 2, 2012 Share Posted August 2, 2012 Why do you think that? If you just said it works... did you actually try it? Quote Link to comment https://forums.phpfreaks.com/topic/266567-mod-rewrite-help/#findComment-1366275 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.