![]() |
need some mod_rewrite help
i read a few tutorials on mod_rewrite but im still stumped.
what i'm wondering is if i have something like this Code:
cart.php?m=product_list&c=7this is what i've tried so far Code:
RewriteEngine On |
Perhaps some one could write a tutorial on this one, because I still suck at writing htaccess.
|
Well, first of all, $1, $2, ..., $n are references to the previously captured groups (stuff between paranthesis, in the order they were created). Second of all, in regex, ^ delimits the beginning of a regular expression, whereas $ represents the end of it. Thirdly, you need to tell apache that it needs to do a URL rewrite, by prefixing rewrite rules with "RewriteRule". So, your rule is wrong right from the beginning of the second line. Here's the correct rule:
Code:
RewriteRule ^products/([0-9]+)$ cart.php?m=product_list&c=$1 [QSA]Now, about the rules effect. Well, they take effect in the moment you save your .htaccess file. Meaning that you will be able to access http://somesite.com/products/7 after you add that rule to your .htaccess. However, it will not replace your current URLs with the rewritten ones. How should apache know which ones should be left intact and which ones should be rewritten? So yes, you need to manually change all URLs you are rewriting. That's why you have to think about URL rewriting (whether you will ever need it or not) BEFORE the actual coding, so you don't have to do the same thing twice. |
The URL provided has been spammed by a so called pr0nbot and I can't any normal topic anywhere. :-P
Yet, some good advise. I just followed a fairly large tutorial on RegEx and it should apply fine to htaccess mod_rewrites, right? Xenon is the master of RegEx is what it looks like. :-P |
thanks xenon! u rock.
these are the rules i wrote based on the cart that i'm using which can be found at digiSHOP :: Shopping Cart Software & Ecommerce :: Products i have to figure out how to change the urls in the application lol thats gonna take forever but if you can please review the rules that i wrote and see if there correct before i impplement it that would be great :) Code:
RewriteEngine Onthanks again. ps: how do i know what flags to put? |
What's the [QSA] for, in the end of the row??
|
Quote:
|
The
QSA flag stands for "query-string append". The query string (if any) of the request will be tacked onto the end of the rewritten URL if you use this flag. |
Ye, I found explenation on mod_rewrite forum..
[QSA] stands for Query String Append. This means the 'query string' (stuff after the ?) should be passed from the original URL (the one we are rewriting) to the new URL. |
so can someone see if i did the rules correctly or if any fixes needed? thanks
|
You forgot the regex begin tag on this line:
Code:
RewriteRule Search/$ cart.php?m=search |
| All times are GMT. The time now is 02:39 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0