0

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
4
Views
5 Years
Discussion Span
Last Post by weekendrockstar
1

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.

Edited by diafol

0

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.

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.