ngreenwood6 Posted October 3, 2009 Share Posted October 3, 2009 Can someone show me a basic example of how to rewrite a url? I have urls like this: http://www.mysite.com/dashboard.php I want to show that url as: http://www.mysite.com/dashboard/ Another url I will have is: http://www.mysite.com/?method=validate_email&email=my@email.com&valid_code=random_here I would like that to be something like: http://www.mysite.com/validate_email/ Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/176363-mod_rewrite/ Share on other sites More sharing options...
ngreenwood6 Posted October 3, 2009 Author Share Posted October 3, 2009 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929745 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Are you being specific in as much as they are the pages you wish to forward, or are they supposed to give an idea of the pattern you wish to use. Using a dynamic method they contradict each other. Quote Link to comment https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929761 Share on other sites More sharing options...
ngreenwood6 Posted October 3, 2009 Author Share Posted October 3, 2009 Yeah they are 2 types of urls I have. I thought you could make multiple rules. The first one just to take off the .php at the end of the file and the second to make the url whatever the method from the get is Quote Link to comment https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929763 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 It sounds like your thinking of that back to front. The objective of a mod_rewrite would be to add the .php onto the end. So when the user types http://www.mysite.com/cool-page-here/ what mod_rewrite would do is make it so that the page they actually see is http://www.mysite.com/index.php?id=cool-page-here Quote Link to comment https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929764 Share on other sites More sharing options...
ngreenwood6 Posted October 3, 2009 Author Share Posted October 3, 2009 Yeah that is what I am trying to do with the second url but with the first one I just dont want them seeing the actual filename. For example www.mysite.com/dashboard.php becomes www.mysite.com/dashboard/. The second one would be www.mysite.com/?method=validate_email&email=some@email.com&pass_code=random_here which would turn into www.mysite.com/validate_email/, so that it just shows the method. Quote Link to comment https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929767 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Maybe it's a communication thing... You keep saying turn www.mysite.com/?method=validate_email&email=some@email.com&pass_code=random_here into www.mysite.com/validate_email/ implying that you wish the user to enter the first and the URL to display the second, thats not how it works. As far as I know that would be impossible because mod_rewrite doesn't change the value in the address bar at all. Quote Link to comment https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929774 Share on other sites More sharing options...
ngreenwood6 Posted October 3, 2009 Author Share Posted October 3, 2009 no the page is a link. so the link says that but when they actually go to the page I want them to see /validate instead of method=validate Quote Link to comment https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929832 Share on other sites More sharing options...
ngreenwood6 Posted October 3, 2009 Author Share Posted October 3, 2009 ok so scratch that I was confused lol. I want this link http://mysite.com/validate_email/some_emal/some_pass_code to refer to this http://mysite.com/?method=validate_email&email=some_email&pass_code=some_pass_code. Quote Link to comment https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929835 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Ok, that is much more like it, that should be possible, I haven't got time to look at it atm, but if nobody else replies I'll have a look in teh morning. The basic theory is this... Options +FollowSymLinks RewriteEngine On RewriteRule /(.+?)/(.+?)/(.+?) /file.php?item1=$1&item2=$2&item3=$item3 ... bare in mind that probably doesn't work, I just mocked it up to give you an idea. But that will obviously try and parse any file on your site to that Rule, you will also need to use RewriteCond to choose what to forward. Quote Link to comment https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929841 Share on other sites More sharing options...
ngreenwood6 Posted October 4, 2009 Author Share Posted October 4, 2009 so to start out I have this code: RewriteEngine on RewriteRule ^([A-Za-z0-9\_\-]+)$ index.php?method=$1 RewriteRule ^([A-Za-z0-9\_\-]+)\/$ index.php?method=$1 I figured that out by looking at other code. The second rewrite rule I made just incase the users adds a slash at the end of the url. It is using the same method but when i try putting the slash on the end it isnt working. Any ideas why? Quote Link to comment https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-930014 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.