Forum Moderators: phranque
I am trying to rewrite a url like this "www.example.com/sectionname/categoryname/pageidname" to "www.example.com/index.php?section=sectionname&category=categoryname&pageid=pageidname"
this should be fairly simple from what I have read, but I cannot get it to work. I found this:
"RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?product=$1&color=$2&size=$3&texture=$4&maker=$5 [L]"
but when I reformat it to work for me it doesn't work and I get a 404 error.
My .htaccess file:
"RewriteEngine on
RewriteBase /directory/
RewriteCond %{REQUEST_URI}!/index\.php
RewriteCond %{REQUEST_URI}!\.jpg$
RewriteCond %{REQUEST_URI}!\.png$
RewriteCond %{REQUEST_URI}!\.gif$
RewriteCond %{REQUEST_URI}!\.css$
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /direcotry/index.php?section=$1&category=$2&pageid=$3 [L]"
if I write it like this it works:
"...
RewriteRule ^([^/]+)/?$ /directory/index.php?section=$1 [L]"
but i cannot get it to work with more than one variable. Please help. Thanks very much in advance.
For url /sectionname/categoryname/pageidname, and all 'shorter' URL versions, I'd suggest:
RewriteCond %{REQUEST_URI} !(\.(jpg¦png¦gif¦css)¦/index\.php)$
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /directory/index.php?section=$1&category=$2&pageid=$3 [L]
#
RewriteCond %{REQUEST_URI} !(\.(jpg¦png¦gif¦css)¦/index\.php)$
RewriteRule ^([^/]+)/([^/]+)/?$ /directory/index.php?section=$1&category=$2 [L]
#
RewriteCond %{REQUEST_URI} !(\.(jpg¦png¦gif¦css)¦/index\.php)$
RewriteRule ^([^/]+)/?$ /directory/index.php?section=$1 [L]
RewriteRule index.php$¦\.(jpg¦png¦gif¦css)$ - [S=3]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /directory/index.php?section=$1&category=$2&pageid=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ /directory/index.php?section=$1&category=$2 [L]
RewriteRule ^([^/]+)/?$ /directory/index.php?section=$1 [L]
Replace all broken pipe "¦" characters in the code above with solid pipe characters (Shift-\ on most U.S. keyboards) before use; Posting on this forum modifies the pipe characters.
If you get 404 errors (or any others), examine your server error log -- The information it contains will often tell you exactly what is wrong.
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim