never_rain Posted January 18, 2010 Share Posted January 18, 2010 Hi, I am new into this. However, I have been using one line Rewrite rule to rewrite those URL's that are using single variable. Here is what is in my .htaccess RewriteRule ^(.*)\.html$ /index.php?pg=detail&catTitle=$1 [nc] and the a href code is as follows. <a href="<?=$webPath?><?= str_replace(' ', '-', $viewcat['contentURL'])?>.html" > Till here it works perfectly. Now I wish to re write for category. Here is what I am trying to do RewriteRule ^category/(.*)/(.*).html$ /index.php?pg=dssGallery&catId=$1&catTitle=$2 [nc] here is the a href code. <a href="<?=$webPath?>category/<?= $viewcat1[pk_id]?>/<?= str_replace(' ', '-', $viewcat1[cat_Title])?>.html" > Now the problem is.. The second rule is also going to the first page. It's not reading the second rule at all. Please take a look and let me know where I am wrong. I'll be really greatfull. Quote Link to comment https://forums.phpfreaks.com/topic/188942-second-variable-not-picking-the-values/ Share on other sites More sharing options...
mga_ka_php Posted January 19, 2010 Share Posted January 19, 2010 try adding \ before .html Quote Link to comment https://forums.phpfreaks.com/topic/188942-second-variable-not-picking-the-values/#findComment-997734 Share on other sites More sharing options...
wildteen88 Posted January 19, 2010 Share Posted January 19, 2010 Your PHP code is fine. Its your rewriterules which are at fault. I do not recommend using (.*) as it is greedy. You should be more specific with your regex partterns. Such as if you want to match only numbers use ([0-9]+), or for strings use ([A-Z0-9\-_]). I'd setup your rules as such RewriteRule ^category/([0-9]+)/([A-Z0-9\-_]).html$ /index.php?pg=dssGallery&catId=$1&catTitle=$2 [L,NC] RewriteRule ^([A-Z0-9\-_])\.html$ /index.php?pg=detail&catTitle=$1 [L,NC] Quote Link to comment https://forums.phpfreaks.com/topic/188942-second-variable-not-picking-the-values/#findComment-998179 Share on other sites More sharing options...
cags Posted January 22, 2010 Share Posted January 22, 2010 Your PHP code is fine. Its your rewriterules which are at fault. I do not recommend using (.*) as it is greedy. You should be more specific with your regex partterns. Such as if you want to match only numbers use ([0-9]+), or for strings use ([A-Z0-9\-_]). I'd setup your rules as such RewriteRule ^category/([0-9]+)/([A-Z0-9\-_]).html$ /index.php?pg=dssGallery&catId=$1&catTitle=$2 [L,NC] RewriteRule ^([A-Z0-9\-_])\.html$ /index.php?pg=detail&catTitle=$1 [L,NC] Just out of curiosity wildteen88, why choose to escape the dash rather than simply place it after the underscore? [A-Z0-9_-] I assume this Regex convention passes through to mod_rewrite. At the end of the day it makes no difference, I'm just wondering if you have a reason for doing it that way. Quote Link to comment https://forums.phpfreaks.com/topic/188942-second-variable-not-picking-the-values/#findComment-999889 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.