We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,078 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Mod_Rewrite and GET values

I am looking to use mod_rewrite to remove the file extension of the files on my site. I am aware of how to make use of the mod but I was curious as to a couple of things when passing variables to a script. Such as if I have a file 'profiles.php' and I want to offer a link to view a specific profile would the link point to 'profiles?profile_id=#'? I am not certain if mod_rewrite will disrupt the script's use of the GET superglobal. And of course this would also go for form submissions. If I had a form to submit changes to a user's profile should iI then use 'form action=save_profile'. So believe that this should work as sending info by POST it isn't sent through the URL.

This isn't a huge deal as it's just something that I would like to do if it won't be too much of a headache. I wouldn't mind putting in the time to update links and form actions throughout my site but if it is going to require more work than that then it may not be worth it to me.

Thanks in advance for any ideas.

2
Contributors
3
Replies
3 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
weekendrockstar
Junior Poster in Training
71 posts since Dec 2010
Reputation Points: 25
Solved Threads: 16
Skill Endorsements: 0

Your rewrite will just let the server know that the url like .../profiles/12345/ actually means .../profiles.php?id=12345. You can still type in the full ugly url to the address bar and it will work. You need to change your link addresses to the new form if your want them to display properly in the address bar.

Change the form actions too to the new format.

diafol
Keep Smiling
Moderator
10,655 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,511
Skill Endorsements: 57

Ohhhhh gotcha! I wasn't positive if mod_rewrite would just 'nullify' the file's extension. I know of the method you show but I wasn't sure if that was the default behavior or if that was a spefic behavior. You don't have to check it out but I was referring to this article where it seems to explain a method to only remove the extension.

I would like to go the route in your post but then I am not sure how to handle when there are several different key/value pairs behing sent. However, I will research it further. Again, I do like the idea and as long as it requires changing only link and form actions (in addition to the .htaccess part as well of course) then I will probably go that route. But now I can go research a little further to make sure that I get this right. Much appreciated.

weekendrockstar
Junior Poster in Training
71 posts since Dec 2010
Reputation Points: 25
Solved Threads: 16
Skill Endorsements: 0

Actually I figured it out without much further research. And I had also forgotten that my original search term was for "mod_rewrite to remove file extension"...which would explain why the article had that specific function in mind.

weekendrockstar
Junior Poster in Training
71 posts since Dec 2010
Reputation Points: 25
Solved Threads: 16
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0660 seconds using 2.68MB