
|
View Full Version : making simple php urls
DJ-Sound 06-06-2004, 02:59 PM ok What I am trying to attempts is:
Making dynamic pages look static without mod_rewrite
I found an article here: http://www.stargeek.com/php-seo.php
but I don't know where to place the $ Ln books.php books (example in article)
can someone please read the above article and help out a confused person :eek:
Thanks,
-Ryan
DJ-Sound 06-06-2004, 03:10 PM I think i get it now, am I supposed to creat say a file with no extension called books and have it link to books.php
and in the books.php file I need to add:
<?php
function processURI() {
$request = explode("/",$_SERVER["REQUEST_URI"]);
$count = count($request);
for ($i = 1 ; $i < $count ; $i++) {
$values["arg".$i] = $request[$i];
}
return $values;
}
?>
and the url defining codes:
<?php
$vals = processURI();
$_GET[$vals[1]] = str_replace(".html", "", $vals[2]);
?>
am I right? can someone please review the article and let me know if I have the right idea!
Thanks
Epagien 06-06-2004, 04:28 PM $ Ln books.php books
This links books.php to the books file. If you edited books.php it would edit books.
After reading the article, this is how I understood the setup at first glance. Please note I have not tested the code:
books - a file without a file extension
books.php - linked to books for easier editing.
You would need access to server commandline to perform link.
.HTACCESS
<Files books>ForceType application/x-httpd-php</Files>
HTACCESS forces the file books to be processed as a php file.
Now looking at code:
<?php
function processURI() {
$request = explode("/",$_SERVER["REQUEST_URI"]);
$count = count($request);
for ($i = 1 ; $i < $count ; $i++) {
$values["arg".$i] = $request[$i];
}
return $values;
}
?>Diagram of domain.com/books/page/
domain.com/ - Your domain obviously.
books - The php script hidden as a directory
/page/ - The REQUEST URI'REQUEST_URI'
The URI which was given in order to access this page; for instance, '/index.html'.
The REQUEST URI should be around the lines of /book/page/. When the function PROCESSURI() is called it will retrieve and process the REQUEST_URI, and then explode the results into an array and returned to the execution point, which would be $vals according to the second set of code.
<?php
$vals = processURI();
$_GET[$vals[1]] = str_replace(".html", "", $vals[2]);
?>$vals[1] would be books and $vals[2] would be page. This is just an explanation of the article and I would like someone with more experience to review the article.
My question is how does index.php get the REQUEST_URI of domain.com/books/page/ that is how the article writer has it setup. I figured domain.com/books/page called the books script.
DJ-Sound 06-06-2004, 05:48 PM I am testing this with: http://www.prodjfinder.com/classifieds/index.php?method=showhtmllist&list=classifiedscategory&rollid=11&fromfromlist=classifiedscategory&fromfrommethod=showhtmllist&clearoff=1
I want to equal prodjfinder.com/usa/xxx.php or even just /usa.php to be able to get my dynamic website on google.
does anyone know of a better way of doing this?
sasha 06-06-2004, 05:57 PM You can try this, but it IS using mod_rewrite
http://tnt.goldnet.ca/work/rewrite (u=wht, p=wht)
I described it here, but got no comments for it:
http://www.webhostingtalk.com/showthread.php?s=&threadid=250612
Epagien 06-06-2004, 10:54 PM Ok, I ran some tests and came up with a functional script. This will setup a USA script.
/classifieds/usa/
Step 1
Create a .htaccess at root level, '/'. Its the first level you see when you login via FTP. The .htaccess file should have the following text.
<Files usa>
ForceType application/x-httpd-php
</Files>
Step 2
Now go to the classifieds folder and create a blank file called 'usa.'
Add the following code to the top of the 'usa' file.
// Retrieve REQUEST_URI
// Remove the current script name
$raw = $_SERVER['REQUEST_URI'];
$parent_directory = "/classifieds"; // No Trailing /
$additional = "/usa/";
$raw = str_replace($parent_directory,"",$raw);
$raw = str_replace($script_name,"",$raw);
// Explode REQUEST_URI into array
$raw = explode("/",$raw);
Now for an explanation of code. Here is the crude version of the webpage; dissected
Script Path
prodjfinder.com/classifieds/index.php
QUERY_STRING
?method=showhtmllist
&list=classifiedscategory
&rollid=11
&fromfromlist=classifiedscategory
&fromfrommethod=showhtmllist
&clearoff=1
URL Version
http://www.prodjfinder.com/classifieds/index.php?method=showhtmllist&list=classifiedscategory&rollid=11&fromfromlist=classifiedscategory&fromfrommethod=showhtmllist&clearoff=1
Now here is the refined version; dissected
Script Path
prodjfinder.com/classifieds/usa/
REQUEST_URI
showhtmllist/
classifiedscategory/
11/
classifiedscategory/
showhtmllist/
1/
URL Version
http://www.prodjfinder.com/classifieds/usa/showhtmllist/classifiedscategory/11/classifiedscategory/showhtmllist/1/
Step 3
Now all you have to do is replace all your references to $_GET variables to $raw[0...5].
Example
$_GET[rollid] would be $raw[2] = 11
And thats the way I would do it. It can be improved on obviously; but I did it in a few minutes.
DJ-Sound 06-06-2004, 11:15 PM I appreicate your help! I will try this as soon as I get my server online, my current hosting company does not allow .htaccess files as I just now learned......
Thanks!
DJ-Sound 06-06-2004, 11:20 PM Also can google index say the url: http://prodjfinder.com/classifieds/index.php?rollid=11
Because I find the rollid= is the only thing that determins where the url leads to....
Epagien 06-06-2004, 11:38 PM Ah... Bummer on the '.htaccess not allowed'
You could try
http://prodjfinder.com/classifieds/index.php/11/
and replace the $script_name variable with /index.php/
and see if that works.
Try printing $raw[0]; and see if it comes out with 11.
If this works, then maybe the google robots will read the address as /index.php/ being a directory instead of a script. I've seen it done somewhere...:)
DJ-Sound 06-06-2004, 11:58 PM I can't risk that screwing something else up ;)
I will have my own web server online within a few days, I will just get the mod_rewrite module, its much more simple :)
Thanks,
-Ryan
Epagien 06-07-2004, 12:10 AM [NOTICE ERROR IN MY PRIOR CODE]
$additional = "/usa/";
Mistake from testing code on my own machine
$script_name = "/usa/";
// Retrieve REQUEST_URI
// Remove the current script name
$raw = $_SERVER['REQUEST_URI'];
$parent_directory = "/classifieds"; // No Trailing /
$script_name = "/index.php/";
$raw = str_replace($parent_directory,"",$raw);
$raw = str_replace($script_name,"",$raw);
// Explode REQUEST_URI into array
$raw = explode("/",$raw);
This code will work without .htaccess. You just have to see if it tricks google to thinking its a static file.
A little on mod_rewrite, it still requires .htaccess and depending on what you want to do it can be even more complex than this.
|