I couldn’t do it any shorter :-/
I’m having a problem with my php project concerning redirects and $_GET.
I hope you will help me 🙂
Lets say I have these 3 folders in the root of my Webserver.
/root
/themes
/page.php
/project1
/index.php
/content.php
/project2
/index.php
/content.php
/themes contains a php file called /page.php
/page.php contains a dynamic PHP/HTML structure or theme, which I can use for different content files.
/project1 and /project2 contain mostly HTML content files which get included by /page.php.
/project1 and /project2 are the root folders for 2 different domains, so each contains an index.php.
Now the problem:
In order to get the websites for each domain to work I have to redirect the user to /themes/page.php, because thats where the functionality is and then include the correct content files.
To let /page.php know what content file out of /project1 or /project2 it has to load I use a redirect for index.php to fill $_GET ,like this :
header("Location: root-domain/themes/page.php?path=project1&file=content1");
That way page.php gets to know the path and filename of the requested file, by taking it from GET.
BUT:
That way the user gets to know each folder and each filename, even of some php files. I don’t know if that’s good?
And the URL changes from the requested URL into the URL of my webserver root.
Does one know a better solution?
Thanks! <3
Actually, I think there is a solution, you just need to use mod_rewrite, which is a module for Apache. With that, you could redirect all your URL requests to this one specific page of yours. Unfortunatelly, the "magic" behind mod_rewrite is little bit more complex, so I recommend you this documentation for further uses.
But for now, just check if you have a mod_rewrite turned on in server configuration, then simply create a file called .htaccess in directory project1 (or any other) and insert this little piece of code in it:
Hit save, and that should be it. Now every page request goes through /themes/page.php.
And by the way, you definitely shouldn’t be exposing script names in url.