Page 1 of 1
mod_rewrite module to change php urls
Posted: Mon Dec 16, 2002 5:03 pm
by fariquzeli
I'm using the mod_rewrite module to make some of my urls "search-engine friendly" and I've got the first RewriteRule working just fine, the pages are renamed perfectly, but the second and third rules (which are almost identical) don't seem to work
Here is what I have written in my .htaccess file
Code: Select all
RewriteEngine On
RewriteRule ^(.*)\.phtml$ index.php?pname=$1
RewriteRule ^(.*)\.phtml$ products.php?type=$1
RewriteRule ^(.*)\.phtml$ detail.php?urltitle=$1
an example of a workign rule is the first one
http://www.youngdental.com/index.php?pname=about is also:
http://www.youngdental.com/about.phtml
although the second rule does not work, as doesn't the third:
http://www.youngdental.com/products.php?type=dpa should point to:
http://www.youngdental.com/dpa.phtml
but the entry shows up blank for the second one. Anyone know where I am going wrong?
Posted: Mon Dec 16, 2002 5:11 pm
by mydimension
that is because both of those urls match the first pattern. you need to define a pattern that is unique to all of those so that mod_rewite can differentiat between them.
Posted: Mon Dec 16, 2002 5:16 pm
by fariquzeli
can you give me an example? Sorry, I'm sort of new to mod_rewrite
Posted: Mon Dec 16, 2002 9:15 pm
by mydimension
for this particular example this would work:
Code: Select all
RewriteEndinge On
RewriteRule ^products/(.*)\.phtml$ products.php?type=$1
RewriteRule ^details/(.*)\.phtml$ detail.php?urltitle=$1
RewriteRule ^(.*)\.phtml index.php?pname=$1
granted you will have to change most of your links around but this was the easiest solution for me to come up with.
Posted: Tue Dec 17, 2002 11:58 am
by fariquzeli
now with this code:
Code: Select all
RewriteEngine On
RewriteRule ^products/(.*)\.phtml$ products.php?type=$1
RewriteRule ^details/(.*)\.phtml$ detail.php?urltitle=$1
RewriteRule ^(.*)\.phtml index.php?pname=$1
The products.php stuff will work, as will the index.php?pname=stuff
but for some resaon the details one (the second one) will not work
http://www.youngdental.com/detail.php?urltitle=carefree should also work as:
http://www.youngdental.com/details/carefree.phtml
but it doesn't, any ideas?
Posted: Tue Dec 17, 2002 1:54 pm
by fariquzeli
anyone?
Posted: Tue Dec 17, 2002 8:46 pm
by mydimension
i think i know whats up. try this:
Code: Select all
RewriteEngine On
RewriteRule ^products/(.*)/\.phtml$ products.php?type=$1
RewriteRule ^details/(.*)/\.phtml$ detail.php?urltitle=$1
RewriteRule ^(.*)/\.phtml$ index.php?pname=$1
Posted: Wed Dec 18, 2002 2:00 pm
by fariquzeli
wouldn't this make the links turn out to be:
products/productName/.phtml
details/detailName/.phtml and
product/.phtml ?
cause none of these worked when I tried it, only when I removed the second / would the links work.
Is there a possibility I'm missing something in my apache config?
Posted: Wed Dec 18, 2002 5:31 pm
by mydimension
sorry, i must have been out of it. your right. as to the problem, im not to sure. seems very odd indeed.
Posted: Wed Dec 18, 2002 8:16 pm
by fariquzeli
its alright, i'll just use the 2 I have working and keep the rest of the links the same.