Jump to content


Your Best Uses

  • Please log in to reply
4 replies to this topic

#1 R_P

  • Members
  • PipPipPip
  • Advanced Member
  • 98 posts

Posted 07 September 2006 - 02:41 AM

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:

    RewriteEngine on
    ReWriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

I was wondering though if anyone could tell me what the flags (NC, R, and L) mean after the RewriteRule.
Pro in: Win2K3S | Apache2 | PHP5 | Perl5 | MySQL | MSSQL | Firefox | Photoshop
Student of: Ubuntu6 | Java | C | VB.NET | ASP.NET
Developer: Roddzilla Webstudios, Burrson CG, DVIDSHUB, The Four Nations
Student: Georgia Tech, Georgia Tech College of Computing

#2 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 September 2006 - 10:52 AM

These flags are explained in the Apache mod_rewrite documentation. Scroll down until you find the following paragraph:

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:

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.

#3 cmgmyr

  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 07 September 2006 - 03:25 PM

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.

RewriteEngine  on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ profile.php?moduser=$1 [L]

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
include "connect.php";
   global $userid, $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 ";
	   $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 ";

**Don't really pay attention to $name, i just use that as a prefix for the title of the page later on.


#4 Monkeymatt

  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 09 September 2006 - 01:08 AM

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.fu....com/tutorials/

Here is the appliciable .htaccess code
RewriteRule ^tutorials/$ tutorials.php?cat_name=Main
RewriteRule ^tutorials/((([^/]+)/)+)$ tutorials.php?cat_name=$1
RewriteRule ^tutorials/((([^/]+)/)+)([^/]+)/examples/([0-9]+)$ tutorials.php?cat_name=$1&tutorial_name=$4&example=$5
RewriteRule ^tutorials/((([^/]+)/)*)([^/]+)/([0-9]+)$ tutorials.php?cat_name=$1&tutorial_name=$4&page=$5
RewriteRule ^tutorials/((([^/]+)/)*)([^/]+)$ tutorials.php?cat_name=$1&tutorial_name=$4&page=1

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.


#5 wild-wing

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 05 October 2006 - 11:19 PM

mind explaing that a wee bit more im confused as to how the heck that works

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users