Jump to content

mod_rewrite


ngreenwood6

Recommended Posts

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 protected]&valid_code=random_here

 

I would like that to be something like:

 

http://www.mysite.com/validate_email/

 

Any help is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/176363-mod_rewrite/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929764
Share on other sites

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 protected]&pass_code=random_here which would turn into www.mysite.com/validate_email/, so that it just shows the method.

Link to comment
https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929767
Share on other sites

Maybe it's a communication thing... You keep saying turn www.mysite.com/?method=validate_email&[email protected]&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.

Link to comment
https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929774
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-929841
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/176363-mod_rewrite/#findComment-930014
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.