Richard_Grant Posted September 13, 2014 Share Posted September 13, 2014 Okay so i have a URL like this.. https://www.mysite.com/board/profile.php?user=1 I want the URL to be like this.. https://www.mysite.com/user/1 .htaccess rewrites have always confused me. Quote Link to comment https://forums.phpfreaks.com/topic/291040-htaccess-write-php-string-query-in-url/ Share on other sites More sharing options...
Ch0cu3r Posted September 13, 2014 Share Posted September 13, 2014 You will first need to edit your PHP script so it outputs the links in the new format. Eg <a href="/user/1">FooBar</a> Then in .htaccess file in the your sites document root. You can use the following rule RewriteEngine On RewriteRule user/(\d+) board/profile.php?user=$1 [NC] To map /user/x to /board/profile.php?user=x 1 Quote Link to comment https://forums.phpfreaks.com/topic/291040-htaccess-write-php-string-query-in-url/#findComment-1490981 Share on other sites More sharing options...
Richard_Grant Posted September 13, 2014 Author Share Posted September 13, 2014 You will first need to edit your PHP script so it outputs the links in the new format. Eg <a href="/user/1">FooBar</a> Then in .htaccess file in the your sites document root. You can use the following rule RewriteEngine On RewriteRule user/(\d+) board/profile.php?user=$1 [NC] To map /user/x to /board/profile.php?user=x Thank you im sure that will work exactly the way i need it to, i will let you know as soon as i finish making the user profile! Quote Link to comment https://forums.phpfreaks.com/topic/291040-htaccess-write-php-string-query-in-url/#findComment-1490991 Share on other sites More sharing options...
Richard_Grant Posted September 13, 2014 Author Share Posted September 13, 2014 im using this: RewriteCond %{REQUEST_URI} user/(.*)/(.*)/ RewriteRule user/(.*)/(.*)/ %{DOCUMET_ROOT}/board/profile.php?ID=$1&NAME=$2 Is that fine? its working fine but is it depreciated or anything? Quote Link to comment https://forums.phpfreaks.com/topic/291040-htaccess-write-php-string-query-in-url/#findComment-1490995 Share on other sites More sharing options...
Richard_Grant Posted September 13, 2014 Author Share Posted September 13, 2014 Ahhh! i just found out that if i type https://www.mysite.com/user/RichardGrant/1 it doesnt recongnize the url because the trailing slash... but this works fine! https://www.mysite.com/user/RichardGrant/1/ Quote Link to comment https://forums.phpfreaks.com/topic/291040-htaccess-write-php-string-query-in-url/#findComment-1490996 Share on other sites More sharing options...
CroNiX Posted September 15, 2014 Share Posted September 15, 2014 Probably because you have a trailing slash in the RewriteCondition Quote Link to comment https://forums.phpfreaks.com/topic/291040-htaccess-write-php-string-query-in-url/#findComment-1491194 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.