htaccess php5

I was going over some of my old stuff that worked so wonderfully back in php4 and now I just can’t seem to find my bug it may be obvious to someone else.

So what use to happen is you go to website.com/Product/Category_of_product/1.html and I would use php to parse the url and using Mysql indexing get VERY fast loading pages of dynamic content based on how accurate my url was. So the 1.html could be parsed as item number 1 in my database and if we were in a category I could do a search of all products in that category etc. My new problem is not really the php but getting my server to treat the file “Product” as php so that can parse the url like i used to.

What I used to do was modifiy the .htaccess file as such.

[code]php_value error_reporting 7
php_flag display_errors On

RewriteEngine on
Options +FollowSymlinks

<Files “Product”>
ForceType application/x-httpd-php5

<Files “Shared”>
ForceType application/x-httpd-php5

<Files “Catalog”>
ForceType application/x-httpd-php5
[/code]

So The first portion of my old file is as such ( I have in the course of researching this found much better and cleaner ways I intend to implent the parseing of the url but 8 years ago this was golden and it worked for me.)

[php]$expl = explode("/", SELF);
$id = (!empty($_REQUEST[‘str’])) ? $_REQUEST[‘str’] : null;
if(!isset($id))
{
$id = $expl[count($expl)-1];
}
$who = $SERVER[‘SERVER_NAME’];
$id = str_replace ("%20", " “, $id);
$content_title = strtoupper($id);
$id = str_replace (” “, “+”, $id);
$id = str_replace (”
", “+”, $id);
$id = str_replace ("-", “+”, $id);
$id = str_replace (".html", “”, $id);
$str = $id;
$main = str_replace("+", " ", $str);
$main = strtoupper($main);[/php]

At some point I will have to create a script that defines the URL parsing array directly to Database fields so if the url is 5 long or 3 directories long I can be more or less specific in my database searches (The data base has millions of entries and its production so this why its necessary to be conservative in our access of the database.

Using Php 5.3.18 and latest apache 2.2 but the old server was php 4.** and apache 2.0.

So hopefully this little bug jumps out at someone else because I can’t read another forum post on these long drawn out php scripts for “friendly urls” when I know we used to do this way before anyone else and with minimal effort.

I just need apache to see Products as PHP and execute the following symlinks.

Ok i have tried a modification of the .htaccess by one of your senior members in anther post and I get a 403 error which is different I was getting a 500 error.

I changed the htaccess to this.

[code]php_value error_reporting 7
php_flag display_errors On

Options +FollowSymLinks
#Options SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /RewriteCond %{Product} !-f
RewriteCond %{Product} !-d
RewriteRule ^(.+)$

<Files “Product”>
ForceType application/x-httpd-php5

<Files “Shared”>
ForceType application/x-httpd-php5

<Files “Catalog”>
ForceType application/x-httpd-php5
[/code]

Still not right still looking for a specific suggestion to my particular problem.

No quick answers over the weekend I see. Any directional help would be appreciated.

Why was this thread reported?

I stuck it in the code thread instead of help just needed to be moved.

Ok server is at php 5.3.18 and using SuPHP Ruid2 and SuExec.

The .htacess file

[code]

BEGIN MadMidget

Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^.*$ ./index.php # END MadMidget[/code]

I created a tempory index.php file to just test out clean url parsing.

[php]<?php
//remove the directory path we don’t want
$request = str_replace("/mad/pretty/php/", “”, $_SERVER[‘REQUEST_URI’]);
//split the path by ‘/’
$params = split("/", $request);

//keeps users from requesting any file they want
$safe_pages = array(“users”, “search”, “thread”);
if(in_array($params[0], $safe_pages)) {
//include($params[0].".php");
//print “something”;
print ($params[0]);
//print ($params[1]);
//print ($params[2]);
} else {
print “broken url”;
//include(“404.php”);
}

?> [/php]

http://www.madmidget.com/mad/pretty/php/search/anything

That url should print the word anything instead I get a 500 error. Seems fairly straight forward but I am missing something.

Maybe a custom php.ini? add a module to Apache?

have tried a tutorial from another post on this form my implemenation of it is.

[php]<?php

function getRequest()
{
$uri = strip_tags(strtolower(trim($_SERVER[‘REQUEST_URI’])));
$uri = explode(’/’, $uri); array_shift($uri);
if ($uri[0] == ‘index.php’)
{ array_shift($uri); }}

//Usage
$array = getRequest();

if ($array[0] == ‘mad’) {
print “found to be mad”;

} else if ($array[0] == ‘myclass’) {
// maybe instantiate a class
// $myClass = new myclass();
} else if ($array[0] == ‘filename’){
// maybe include a file file
// include ‘./filename.php’;
} else {
//echo a value
echo 'You requested: ’ . $array[0];
}
?>[/php]

Using the .htaccess

[code]# BEGIN MadMidget

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /index.php [L]

END MadMidget[/code]

Now with this example I get the error no file named MAD found. so this is a positive movement in the right direction. What I need it to do is print something on the page so I know that i can start including files as the url dictates.

Ok I wrote a full “how-to” over on my blog so I won’t forget how to do this myself. I find a few years go by and I forget these one off scenerio’s. But I wanted to end this post on (FIXED) Note because it sucks to just read people’s problems and never find answers as I spent 5 days on this and no one jumped in to poke flaws in my methods.

First the .htaccess file
The suPHP config file allows you override some security I was able to do achieve the goal with full security intact…

#suPHP_ConfigPath /home/YOURUSERNAME/public_html


# BEGIN http://www.firebaseSoftware.com
<IfModule mod_rewrite.c>
Options +FollowSymLinks  
RewriteEngine On 
RewriteBase /prettyurl/
RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f  
RewriteRule ^.*$ ./index.php
</IfModule>
# END http://www.firebasesoftware.com

Now for the index.php file that could run a million page site fairly simply and I will be adding to the full cms functionality of being able to do that on my own blog.
While this very very simaliar to my first post the flaw as that I was stripping the very URL that I was trying to parse instead of the fluffy keyword function I was trying to install.
[php]

<?php //Firebasesoftware.com example pretty url starter script free to use and modify. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); header('Pragma: no-cache'); header('Content-Type: text/html'); //remove the directory path we don't want $request = str_replace("fluffy/keyword/stuffing/", "", $_SERVER['REQUEST_URI']); // If you are going to go uber keyword stuff or secure you would need to dynamicly take keywords back out or ignore the first parameters 0-2 //split the path by '/' $params = explode("/", $request); $reverse_params = array_reverse( explode("/", $request)); $direct_data_call = explode(".", $reverse_params[0]); // This will give you a direct call to db and make a dynamic site SUPER FAST use it on unique ID columns and or Primary Keys and USE LIMIT 1 to prevent looping. $safe_pages = array("prettyurl", "search", "thread"); //keeps users from requesting any file they want if(in_array($params[1], $safe_pages)) { // Here is where you would take $param's to variables and start using them in your cool site code. Mine are printed to show the example working. print ($params[0]); // This will usually just be nothing it prior to the first slash print ""; print ($params[1]); // This would be Catagory in a catalog or type of article or some defined mass directory structure completely virutal now. print ""; print ($params[2]); // This would be a subcatgory and an area where you need to start cleaning up the mysql calls in case you don't have what word is here Search engines tend to Guess print ""; print ($params[3]); // Probably best if its a direct mysql call like a ID number or Unique keyed index word something you would have LIMIT 1 on the end of your Mysql to prevent looping load. print ""; print ($direct_data_call[0]);// very targeted data the URL did your search for you. THE REAL REASON FOR PRETTY URLS REDUCED SERVER LOAD. print ""; print ($reverse_params[0]);// demostration of what we exploded for troubleshooting and instructional purpose. } else { print "broken url ".$request."".$_SERVER['REQUEST_URI']; //include("404.php"); Normally this is what you would want here I use the above code to make sure I am getting what I ask for from the url. } ?>

[/php]

Hope the next guy looking for pretty urls in php5 and suphp finds this to be the shortcut he needed.

Some other critque of myself.

Split was deprecated and in 5.3 will generate errors IN FACT it wouldn’t return the array properly when trying to reverse it.

The .htaccess stuff also in the first samples was old thinking and even in example 2 you can’t use php_values in htaccess anymore as it generates a 500 error for even trying to do so. Thus the needs for a custom_php.ini if you need to modify the php.ini.

I own the server company so I can make these changes globally thus I commented out the custom php.ini but left the line to demostrate you may need it to troubleshoot.(I globally turn off php error logging on the server a bad script can right 60 gig of logs in just 48 hours been there. done that.

<Files “Product”>ForceType application/x-httpd-php5 is also deprecated and needs to be dealt with in the php.ini and http.conf on a secure server now.

I have enjoyed talking myself through this hopefully my next problem has more particpates.

Sponsor our Newsletter | Privacy Policy | Terms of Service