progwihz@yahoo.com Posted February 4, 2008 Share Posted February 4, 2008 Url rewrite problems I am having problems with the following url rewrite fragment. RewriteEngine on RewriteRule ^profiles/([A-Za-z])$ /profiles/$1/ [R] RewriteRule ^profiles/([A-Za-z])/$ /profile.php?username=$1 I have urls in the following format http://www.site.com/profiles/profile.php?username=peter and I want to rewrite it as http://www.site.com/profiles/peter The url rewrite statement above does not work, the normal url stil appears in the browser. How can I get to achieve what i want ? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/89372-url-rewrite-problems/ Share on other sites More sharing options...
progwihz@yahoo.com Posted February 4, 2008 Author Share Posted February 4, 2008 I've got some new url rewrite patterns Options +FollowSymLinks RewriteEngine on RewriteRule profile/(.*)/ profile.php?username=$1 RewriteRule profile/(.*) profile.php?username=$1 basically what this should do is convert http://www.site.com/profiles/profile.php?username=FridgeBadger to http://www.site.com/profiles/profile/scoobylol188/ am not sure this will work ! any help Quote Link to comment https://forums.phpfreaks.com/topic/89372-url-rewrite-problems/#findComment-457643 Share on other sites More sharing options...
sunfall Posted February 4, 2008 Share Posted February 4, 2008 RewriteRule ^profile/([^/]+)/?$ profile.php?username=$1 Quote Link to comment https://forums.phpfreaks.com/topic/89372-url-rewrite-problems/#findComment-457700 Share on other sites More sharing options...
madmax Posted February 5, 2008 Share Posted February 5, 2008 The url rewrite statement above does not work, the normal url stil appears in the browser. How can I get to achieve what i want ? Yes, it will "still appear". The browser will know absolutely nothing about the rewrite unless you create it then redirect back to the browser for it to make a new request based on an updated URL. HTTP is a "stateless" protocol/transaction which means that each request is posted then, effectively, dropped and "forgotten". The browser keeps no "tab" on any changes being done by the server and remains oblivious to your rewrites. There is no two-way communication between mod_rewrite and the browser other than by posting a response back. Think of it like snail-mail letter exchange. You can rewrite requests but all these do is change what files are accessed by the server unless you redirect [R] back. The problem then is that the browser, although it may now look "pretty" will post back yet another URL which may then need to be rewritten a 2nd time at the back-end to map to the correct file-location. Messy An alternative might be Javascript to twiddle with the URL bar but I can't personally recommend it. Quote Link to comment https://forums.phpfreaks.com/topic/89372-url-rewrite-problems/#findComment-458214 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.