Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite works...

...well kind of...

         

elgumbo

3:44 pm on Sep 6, 2004 (gmt 0)

10+ Year Member



Hi

I'm using a gallery script which says to put the following rule into my .htaccess file:

RewriteEngine on

RewriteCond %{REQUEST_URI}!.*__Auto-Gallery/wrapper\.php.*
RewriteRule .* /gallery/__Auto-Gallery/wrapper.php [NE,QSA,L]

As far as I can tell, it is meant to forward any requests for the gallery through the wrapper.php file. Fantastic, it works great!

But the problem I have is that any request for any other page on the site is processed through the wrapper.php as well and results in just the gallery being shown. ie. I can't access my home page unless I take out the rules.

I've played around with this rule all day but I can either get the site to show and no gallery or the gallery to show and no site. I can't get both.

Any pointers?

Cheers

jdMorgan

4:06 pm on Sep 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First, we need to understand what the code does:

# IF the requested URI is NOT <anything>__Auto-Gallery/wrapper.php<anything>
RewriteCond %{REQUEST_URI} !.*__Auto-Gallery/wrapper\.php.*
# THEN redirect all requests to yourdomain/gallery/__Auto-Gallery/wrapper.php, don't escape
# special characters, append query strings, do not process subsequent rewriterules
RewriteRule .* /gallery/__Auto-Gallery/wrapper.php [NE,QSA,L]

Since the code is set up to rewrite *anything* that is requested to wrapper.php, that's what it's doing. There's no apparent need to include the NE and QSA flags in that code, but let's leave that subject alone for now.

What you need to do is to figure out how to 'describe' the pages/files/resources that you *do not* want to rewrite. This can be done by taking advantage of something they have in common such as 'all files in subdirectory Bob' or 'all files that don't start with 'gallery', or you may just have to make a list of all of them. Once you have come up with a foolproof way to describe which resources should not be rewritten, you can exclude those resources from being rewritten by modifying the code.

See the references cited in our charter [webmasterworld.com] for more information.

Jim

elgumbo

1:25 pm on Sep 7, 2004 (gmt 0)

10+ Year Member



Hi Jim

Thanks for the pointers. Think I nailed it with :

#if the URL DOES NOT start with ___php
RewriteCond %{REQUEST_URI}!.*__phpAutoGallery/wrapper\.php.*

#AND the URL contains gallery
RewriteCond %{REQUEST_URI} .*gallery.*

#THEN REWRITE the URL
RewriteRule .* /gallery/__phpAutoGallery/wrapper.php [NE,QSA,L]

#ELSE do nothing

Please let me know if you can for see any problems with this method.

Thanks again.

jdMorgan

3:00 pm on Sep 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This comment line does not reflect what the code does:

#if the URL DOES NOT start with ___php
RewriteCond %{REQUEST_URI} !.*__phpAutoGallery/wrapper\.php.*


In order to specify "Starts with", you'll need to start-anchor the pattern and get rid of the leading ".*" :

RewriteCond %{REQUEST_URI} [b]!^__p[/b]hpAutoGallery/wrapper\.php

You can also leave off the trailing ".*" -- it is entirely redundant. See the regular-expressions tutorial cited in our forum charter (forum link is at top left).

Also, I assume the comment should read "#if the URL DOES NOT start with ___phpAutoGallery/wrapper\.php"

Jim