SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2005
    0 Post(s)
    0 Thread(s)

    Rules affecting each other?

    I'm attempting to perform a rewrite with the .htaccess file below

    RewriteEngine on
    RewriteRule ^public/wiki/(.*)$	/wiki/$1%{QUERY_STRING}		[L]
    RewriteRule    ^(cp|public)/(.*)$	$1.php/$2    		    	[L]
    what's supposed to happen is that when there's a hit on, the url should be rewritten to, along with the atom and url parameters.

    Right now, its not happening. though i'm not sure whether the presence of another .htaccess file is causing any other behaviour. In the wiki directory, there is a .htaccess file with the following rules

    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond	%{REQUEST_FILENAME}  -d
     RewriteRule ^(.*/[^\./]*[^/])$ $1/
     RewriteRule ^(robots\.txt)$ robots.txt [L]
     RewriteRule ^(favicon\.ico)$ favicon.ico [L]
     RewriteRule ^(.*)$ wakka.php?wakka=$1 [QSA,L]
    giving me a bad case of the heebee jeebees, this is.....

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    20 Post(s)
    3 Thread(s)

    Okay, I'm NOT sure what your question is so let me go through your code (some of it really makes NO sense at all! )
    [INDENT]RewriteEngine on[/INCENT]
    Should be RewriteEngine On but that's probably of no effect.
    RewriteRule ^public/wiki/(.*)$ /wiki/$1%{QUERY_STRING} [L]
    Will take requests from public/wiki/whatever and send it to wiki/whatever BUT the way to attach the previous query string is with the QSA flag (your way may actually work, though!).
    RewriteRule ^(cp|public)/(.*)$ $1.php/$2 [L][/CODE]
    Will then take EVERYTHING from the cp and public directories and send it to the EVERYTHING subdirectory of the cp.php or public.php script. Why not the Last flag on this one, too?
    RewriteEngine On
    RewriteRule ^public/wiki/([a-z0-9.-]*)$ wiki/$1 [L]
    Should take care of your "what's supposed to happen" (I HATE that EVERYTHING atom so this will just look for lowercase letters, digits, dots and hyphens - add anything else you're permit inside the square brackets). If you need the previous query string, change the [L] to [QSA,L].

    The other .htaccess file is something else!
    <IfModule mod_rewrite.c>
     RewriteEngine on # okay
     RewriteCond	%{REQUEST_FILENAME}  -d # doesn't seem to be needed
     RewriteRule ^(.*/[^\./]*[^/])$ $1/ # all that to add a trailing slash?
     RewriteRule ^(robots\.txt)$ robots.txt [L] # redundant - should cause a loop!
     RewriteRule ^(favicon\.ico)$ favicon.ico [L] # ditto
     RewriteRule ^(.*)$ wakka.php?wakka=$1 [QSA,L] # This WILL cause a loop
    I'd suggest changing the first line to RewriteEngine Off then specifying what you want to do in this directory before you add RewriteRules (add them after RewriteEngine On but BEFORE RewriteEngine Off).

    I can see why that wiki .htaccess was "giving (you) a bad case of the heebee jeebees!" It did to me, too!

    When you're going to write regex, it's a good approach to identify the pattern of the URL you need to change then what you want to change it to. The pattern should NOT be EVERYTHING (wakka.php redirected to wakka.php) so learn to specify and use RewriteCond(itions) to remove special cases (like wakka.php) before your RewriteRule.


    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts