mod_rewrite module to change php urls

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

mod_rewrite module to change php urls

Post 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?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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.
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

can you give me an example? Sorry, I'm sort of new to mod_rewrite
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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.
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post 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?
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

anyone?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post 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?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

sorry, i must have been out of it. your right. as to the problem, im not to sure. seems very odd indeed.
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

its alright, i'll just use the 2 I have working and keep the rest of the links the same.
Post Reply