Hi
Im trying to write my urls as
product/product_name
rather than
product.php?productid=1
I have come across the apache way, mod_rewrite, and the php way, FilesMatch. But both have the same problem. my style sheet is in a folder in root called styles and images are in images folder and includes etc.
But when I use the url product/product_name, it is using the page product.php?productid=1 except now its looking in the product folder for the styles and images folder. also, none of the links work as again, its looking in the non-existent products folder. I dont really want to have absolute url's for everything. Is there a way around this problem?
Url rewrite problem
Moderator: General Moderators
-
Zander1983
- Forum Newbie
- Posts: 20
- Joined: Mon Mar 21, 2011 2:26 pm
Re: Url rewrite problem
anyone any oidea where i can find out about mod_rewrite? this seems like a blatant flaw in mod_rewrite yet i cant find anywhere on the web where it is addressed...
Re: Url rewrite problem
I had this problem too, but this is a basic description of how I solved it...
You will need the following files:
.htaccess
product <<<NO EXTENSION... and yes, it is a file
//.htaccess file//
NOTE: If you have PHP5 on your server use PHP5 Option
//PHP5 .htaccess//
//products file//
Explanation:
What's happening here, is the ".htaccess" file is making the "products" file PHP and HTML enabled.
In the "products", file the code is finding the url and exploding it to find the $products var.
Use the $products variable to find the product.
Other Tips:
- For include/require or any PHP based files, the "products" file is still in the root directory
- For js/css or any HTML/Client side files, the "products" file acts as the index page for the "products" directory
You will need the following files:
.htaccess
product <<<NO EXTENSION... and yes, it is a file
//.htaccess file//
NOTE: If you have PHP5 on your server use PHP5 Option
Code: Select all
<Files products>
ForceType application/x-httpd-php
</Files>
Code: Select all
<Files products>
ForceType application/x-httpd-php5
</Files>
Code: Select all
<?php
$raw = $_SERVER['REQUEST_URI'];
$url = explode("/",$raw);
$product = $url[1];
?>
What's happening here, is the ".htaccess" file is making the "products" file PHP and HTML enabled.
In the "products", file the code is finding the url and exploding it to find the $products var.
Use the $products variable to find the product.
Other Tips:
- For include/require or any PHP based files, the "products" file is still in the root directory
- For js/css or any HTML/Client side files, the "products" file acts as the index page for the "products" directory