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=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.

Link to comment
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=some@email.com&pass_code=random_here which would turn into www.mysite.com/validate_email/, so that it just shows the method.

Link to comment
Share on other sites

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.

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.