Hello I have a page that contains links.
I need to rewrite these links so that they point to a sub-folder. I need these links to be altered only if they contain a certain string (?option=) in the URL.
Here is what I'd like to achieve:
1. index.php will remain UN-altered
2. index.php?var=1 will remain UN-altered
3. index.php?option=2&var=1 will go to /content/index.php?option=2&var=1
4. otherfile.php?option=2&var=1 will remain UN-altered
I also would like this to take place only for the folder I am currently in so that when I am in the /content folder this URL alteration does not take place, otherwise I suspect it would create an endless loop, right?
In other words every time the page contains a link to the file index.php AND that link contains the 'option' string in the url, I would like that link to change into the same link but in a different folder (the root-folder '/content').
If the page had not been parsed yet I would simply do this:
str_replace('index.php?option=','/content/index.php?option=',$page);
but I can't.
Since the page with the links is being included I have also trying fopen/fread/fclose as well as assigning the include to a variable to later do that str_replace but none of them work because the url I am including has different strings in it too...
Anyway, correct me if I am wrong, but PHP does not have a way to change all the links in a page if the page has already been parsed, right?
If I am wrong please enlighten me.
If I am right then I thought I could achieve this task with a mod alias or mod rewrite but I know NOTHING about these things (I've searched for my issue and stumbled across these concepts). I know very little about RegExp and have no clue about mod url rewriting, but if somebody is good at it and wouldn't mind giving me a quick solution I would greatly appreciate it (and post the results back to the open source commuity)...
I know I am not supposed to ask for ready-made code but I really don't have it in me to learn this apparently complex thing that mod rewrite is just to achieve this one thing I am trying to achieve.
Thanks a lot.