R_P Posted September 7, 2006 Share Posted September 7, 2006 Ha! Actually wanted to be the first to post here. 8) However, I do actually have a point. I'm wondering what your handiest uses are for mod_rewrite. I'm a newb to the module, but have been able to use it in a limited way. One of the things I am most proud of is redirecting traffic to the secure port (443) for certain virtual hosts. Something like this:[code] RewriteEngine on ReWriteCond %{SERVER_PORT} !^443$ RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L][/code]I was wondering though if anyone could tell me what the flags (NC, R, and L) mean after the RewriteRule. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 7, 2006 Share Posted September 7, 2006 These flags are explained in the [url=http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule]Apache mod_rewrite[/url] documentation. Scroll down until you find the following paragraph:[quote]Additionally you can set special flags for Substitution by appending [flags] as the third argument to the RewriteRule directive. Flags is a comma-separated list of any of the following flags:[/quote]Below that it explains what the flags mean, along with other flags too.But here is their names:[L] = Last Rule[NC] = No Case[R] = Force Redirect.More info can be found on these by going to the link above. Quote Link to comment Share on other sites More sharing options...
cmgmyr Posted September 7, 2006 Share Posted September 7, 2006 I've made a Myspace URL type script where users can have their own URL on the site (site.com/name) and it will then be forwarded to the profile page..htaccess[code]RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^([^/\.]+)/?$ profile.php?moduser=$1 [L][/code]In my database I have a moduser field where the script searches, then picks up the userid, then uses the id for the rest of the page.Script in profile.php[code]include "connect.php"; global $userid, $moduser; if(isset($moduser)){ $query = "SELECT * FROM users WHERE moduser = \"$moduser\""; $result = mysql_query($query) or die('Query mod failed: ' . mysql_error()); $countmod = mysql_numrows($result); $userid = mysql_result($result, 0, 'userid'); } if($countmod > 0){ $query2 = "SELECT * FROM users WHERE userid = $userid"; $result2 = mysql_query($query2) or die('Query id failed: ' . mysql_error()); $name = mysql_result($result2, 0, 'name'); $name = stripslashes($name); $name = $name." on "; }else{ $query2 = "SELECT * FROM users WHERE userid = $userid"; $result2 = mysql_query($query2) or die('Query id failed: ' . mysql_error()); $name = mysql_result($result2, 0, 'name'); $name = stripslashes($name); $name = $name." on "; }[/code]**Don't really pay attention to $name, i just use that as a prefix for the title of the page later on.-Chris Quote Link to comment Share on other sites More sharing options...
Monkeymatt Posted September 9, 2006 Share Posted September 9, 2006 I have made a tutorial page with easy to remember urls, that are the categories it is under followed by the tutorial name -- see http://monkeymatt.fusionxhost.com/tutorials/Here is the appliciable .htaccess code[code]RewriteRule ^tutorials/$ tutorials.php?cat_name=MainRewriteRule ^tutorials/((([^/]+)/)+)$ tutorials.php?cat_name=$1RewriteRule ^tutorials/((([^/]+)/)+)([^/]+)/examples/([0-9]+)$ tutorials.php?cat_name=$1&tutorial_name=$4&example=$5RewriteRule ^tutorials/((([^/]+)/)*)([^/]+)/([0-9]+)$ tutorials.php?cat_name=$1&tutorial_name=$4&page=$5RewriteRule ^tutorials/((([^/]+)/)*)([^/]+)$ tutorials.php?cat_name=$1&tutorial_name=$4&page=1[/code]The PHP code then takes the cat names, separates them, and finds the cat id (using all of the cat names allows for categories with same names, just not in the same category). Then it loads the necessary stuff using the names.Monkeymatt Quote Link to comment Share on other sites More sharing options...
wild-wing Posted October 5, 2006 Share Posted October 5, 2006 mind explaing that a wee bit more im confused as to how the heck that works Quote Link to comment 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.