Forum Moderators: phranque
I have dabbled a little bit into mod_rewrite but only know the basics. I am running into a problem. I need the following url:
http://www.example.com/lev2_template.php?lev0=products&lev1=home-and-garden&lev2=bath
to look like this this:
http://www.example.com/products/appliances/air-conditioners/
*** SO... when the user clicks on this:***
http://www.example.com/products/appliances/air-conditioners/
*** They will really be viewing the following url:***
http://www.example.com/lev2_template.php?lev0=products&lev1=home-and-garden&lev2=bath
the problem I am having is that /products/appliances/air-conditioners is a directory - which contains image and configuration php scripts for that particular template page. this is the same problem for each page. I am having trouble getting the mod_rewrite to work when rewriting lev2_template.php to the /air-conditioners directory because it is an existing absolute directory already and wants to display it that way, not as a virtual file. Also, any associated images I have linked to that path, http://www.example.com/products/appliances/air-conditioners/ no longer show up... i am assuming that the mod-rewrite has changed the string somehow dynamically?
Please help! Right now I am using the following- our htaccess already is rewriting any files ending in .php to just the extensionless filename.
Options +FollowSymLinks
RewriteEngine On
DirectoryIndex index.htm
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.php [L,QSA]#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule (.*)/(.*)/(.*)/(.*)/ lev3_template.php?lev0=$1&lev1=$2&lev2=$3&lev3=$4
#RewriteRule (.*)/(.*)/(.*)/(.*) lev3_template.php?lev0=$1&lev1=$2&lev2=$3&lev3=$4
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule (.*)/(.*)/(.*) lev2_template.php?lev0=$1&lev1=$2&lev2=$3
[edited by: phattymatty at 4:02 pm (utc) on Mar. 10, 2008]
However, the likely problem is that your rule won't execute if the requested URL-path exists as a file or as a directory, because that's what the two RewriteConds specify.
If you remove those RewriteConds, then those URLs will be rewritten. BUt this may cause other problems because of the "overlap" of your virtual URL-space with your filespace. You may be happier in the long run if you relocate the script to a unique directory-path.
For the second problem, you'll need to add one or more RewriteConds to exclude image paths, etc. from being rewritten.
Jim