faking PHP page

cnick79

[H]ard|Gawd
Joined
Oct 5, 2004
Messages
1,836
I have a directory on my local apache server that looks like this:

www/
index.php
index.php?page=1

These look like php pages but are actually HTML files. When I go to www/index.php?page=1 the index.php is displayed. When I go to www/index.php%3Fpage=1 then the index.php?page=1 is displayed. How can I get this configured so when I go to www/index.php?page=1 it will display the raw HTML file and not index.php?
 
You could edit the index.php file to check if page=1, and then tell it to file_get_contents() the raw html file (I'm assuming this is a different file other than index.php?). Without seeing the index.php this is tough to guess what you're looking for.
 
Yes, index.php is one file and index.php?page=1 is another file with the file name, index.php?page=1. I did something like this:

file="index.php
Code:
<?php
if (!empty($_SERVER['QUERY_STRING'])) {
  include('index.php?' . $_SERVER['QUERY_STRING']);
} else {
  include('index.php?');
}

The php files do not have <?php inside them. They are actually HTML files. I think I need to get the server to return html instead of php because I'd rather not have to code this?
 
Last edited:
Yes, index.php is one file and index.php?page=1 is another file with the file name, index.php?page=1.
This part doesn't make sense to me. I expect ?page=1 to be the query string and not part of the file name. Is there actually a file on the server named
Code:
index.php?page=1
? I wouldn't expect that to be an allowed filename.

I did something like this:

file="index.php
Code:
<?php
if (!empty($_SERVER['QUERY_STRING'])) {
  include('index.php?' . $_SERVER['QUERY_STRING']);
} else {
  include('index.php?');
}

The php files do not have <?php inside them. They are actually HTML files. I think I need to get the server to return html instead of php because I'd rather not have to code this?

This is also confusing. It sounds like you want the user to be able to hit index.php and serve a dynamic page (even if it is just static html) based on the provided query string, but then you go on to say you'd rather not have to have the code to do the dynamic content?
 
There is a file named index.php?page=1. These are not actual php files but html files as a result of a wget.
 
I created an entry.php file that all .php pages go to, and inside this script I include the URL.

entry.php
Code:
<?php
include(ltrim($_SERVER['REQUEST_URI'], '/'));

.htaccess
Code:
RewriteEngine on
RewriteRule ^(.*).php$ entry.php?$1 [L,QSA]
 
I think you should check out mod_rewrite.
It allows the apache server to make simple decisions on how to serve files. Sorry, but too rusty to give the answer, but I think you should be on your way with that bit of info.
 
Last edited:
I think you should check out mod_rewrite.
It allows the apache server to make simple decisions on how to serve files. Sorry, but too rusty to give the answer, but I think you should be on your way with that bit of info.

I tried something like this, by trying to get my .htaccess to escape ? to %3F but didn't have much luck. I was probably doing it wrong...
 
Back
Top