10-06-2008, 09:01 PM
#1
Super Deity (Level 18)
Join Date: Mar 2001
Location: 127.0.0.1
Posts: 4,035
Mod Rewrite Question
Hello,
I am having a hard time with a rewrite rule. I would like to make it so that mysite.com/category_name.html rewrites to fetch_templates.php?cat_name=category_name
Is something like this possible? The following doesn't seem to be working properly:
Code:
RewriteRule (.*).html fetch_templates.php?cat_name=$1
Add to del.icio.us
Can you digg it?
10-07-2008, 02:58 AM
#2
Blonde Bimbo
Join Date: Jul 2004
Posts: 2,415
You must have some other conflict because this works for me on it's own in .htaccess
Code:
RewriteEngine On
RewriteRule (.*).html fetch_templates.php?cat_name=$1
¥
__________________
I may have opened the door, but you entered of your own free will
Add to del.icio.us
Can you digg it?
10-07-2008, 09:02 AM
#3
Super Deity (Level 18)
Join Date: Mar 2001
Location: 127.0.0.1
Posts: 4,035
Hmm, that's what I was using. I was seeing some funky behavior. I'm gonna try it again after work and get back.
Add to del.icio.us
Can you digg it?
10-07-2008, 09:46 AM
#4
Blonde Bimbo
Join Date: Jul 2004
Posts: 2,415
One possibility is that you have lines after that in htaccess in which case add [QSA,L] after the rule ( Query String Attach, Last )
Code:
RewriteRule (.*).html fetch_templates.php?cat_name=$1 [QSA,L]
¥
__________________
I may have opened the door, but you entered of your own free will
Add to del.icio.us
Can you digg it?
10-07-2008, 09:49 AM
#5
Super Deity (Level 18)
Join Date: Mar 2001
Location: 127.0.0.1
Posts: 4,035
I did have additional rules after it so that was probably it. Thanks, I'll give this a try and see if it works.
Add to del.icio.us
Can you digg it?
10-08-2008, 08:48 PM
#6
Super Deity (Level 18)
Join Date: Mar 2001
Location: 127.0.0.1
Posts: 4,035
Seems to work perfectly, thanks (sorry I cant give you any more rep right now).
Add to del.icio.us
Can you digg it?
10-08-2008, 09:57 PM
#7
Super Deity (Level 18)
Join Date: Mar 2001
Location: 127.0.0.1
Posts: 4,035
Actually there is one thing that is annoying me, it's not a big deal but if it can be fixed that would be great.
This rewrite rule works fine if I do:
xhtml-css-templates.html
The problem is it also works fine if I put something else after .html, such as:
xhtml-css-templates.html23213123124
Is there anyway so that the latter will not work?
Add to del.icio.us
Can you digg it?
10-09-2008, 01:48 AM
#8
Blonde Bimbo
Join Date: Jul 2004
Posts: 2,415
This should work
Code:
RewriteRule (.*).html$ fetch_templates.php?cat_name=$1 [QSA,L]
¥
__________________
I may have opened the door, but you entered of your own free will
Add to del.icio.us
Can you digg it?
10-09-2008, 01:27 PM
#9
Super Deity (Level 18)
Join Date: Mar 2001
Location: 127.0.0.1
Posts: 4,035
That seems to do the trick but now I'm running in to another issue (sorry to keep bugging). Here is my htaccess file:
Code:
RewriteEngine on
RewriteRule p/(.*)/(.*) fetch_templates.php?cat_name=$1&page_num=$2
RewriteRule p/(.*)/(.*)/ fetch_templates.php?cat_name=$1&page_num=$2
RewriteRule templates/(.*).html$ display_template.php?id=$1
RewriteRule (.*).html$ fetch_templates.php?cat_name=$1 [QSA,L]
So anytime someone puts in mysite.com/templates/25.html it should call display_template.php?id=25. However, it actually calls fetch_templates.php?cat_name=25. Is there a way to get around this? I noticed if I change RewriteRule templates/(.*).html$ display_template.php?id=$1 to RewriteRule templates/(.*).htm$ display_template.php?id=$1 it works fine.
Add to del.icio.us
Can you digg it?
10-09-2008, 03:08 PM
#10
Blonde Bimbo
Join Date: Jul 2004
Posts: 2,415
I'm guessing it's because it matches the last and 2nd last rule, you need to tell it to stop on first match
Code:
RewriteEngine on
RewriteRule p/(.*)/(.*) fetch_templates.php?cat_name=$1&page_num=$2 [QSA,L]
RewriteRule p/(.*)/(.*)/ fetch_templates.php?cat_name=$1&page_num=$2 [QSA,L]
RewriteRule templates/(.*).html$ display_template.php?id=$1 [QSA,L]
RewriteRule (.*).html$ fetch_templates.php?cat_name=$1 [QSA,L]
¥
Comments on this post
__________________
I may have opened the door, but you entered of your own free will
Add to del.icio.us
Can you digg it?
10-31-2008, 07:10 PM
#11
Battler (Level 3)
Join Date: Aug 2008
Posts: 22
Thanks, these helped me finally figure some rules out on my site thats been redirecting things all crazy
Add to del.icio.us
Can you digg it?
KEEP TABS
SPONSORS