Gossamer Forum
Quote Reply
Mod rewrite
I'm trying to create a mod rewrite for my main directory. I do not want to have a http://myurl.com/linksdir <-- directory.

Here is what I would think would work:

Code:

RewriteEngine on
RewriteBase /
RewriteRule ^/?$ /cgi-bin/page.cgi [L]
RewriteRule ^(.+) /cgi-bin/page.cgi?g=$1 [L]


But then I realized it could not get to any existing folder, a.k.a. the style sheet. Since I would want access to it, my images, and any new folder I create, I am lost.

After thinking and learning, I came to the conclusion that I am going to have to declare each folder separately. (Please correct me if there is a better way!) So I tried something like this:

Code:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^.*/static/
RewriteCond %{REQUEST_URI} !^.*/images/
RewriteRule ^/?$ /cgi-bin/page.cgi [L]
RewriteRule ^([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?/?$ /cgi-bin/page.cgi?g=$1 [L]


I copied the last line from a random website. It seems to work great, except it does not read html pages: i.e. a detailed new page. Also, I'm guess my folders can only be 4x deep. I don't want to have to expand the regular expression every time I want to create a folder deeper. I appologize in advance if this thread is redundant. Please help.

Thanks,

- Jonathan
Quote Reply
Re: [jdgamble] Mod rewrite In reply to
Well, this works for these two folders for now:

Code:

RewriteEngine on
RewriteRule ^images/(.*) images/$1 [L]
RewriteRule ^static/(.*) static/$1 [L]
RewriteRule ^/?$ /cgi-bin/page.cgi [L]
RewriteRule ^(.+) /cgi-bin/page.cgi?g=$1 [L]




Here is my question, instead of adding a new line of code everytime I create a folder:

Is there a way to automatically goto the directory IF the directory exists????????????????????????

- Jonathan

Last edited by:

jdgamble: Sep 8, 2006, 9:25 PM
Quote Reply
Re: [jdgamble] Mod rewrite In reply to
http://httpd.apache.org/docs/2.2/misc/rewriteguide.html

Section "Search pages in more than one directory" seems to deal with what you are trying to accomplish.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Mod rewrite In reply to
Thanks, but that is not exactly what I need. What I need is this pseudocode:

Code:

RewriteEngine On

if directory (from query_string) exists
then print directory
else

RewriteRule ^/?$ /cgi-bin/page.cgi [L]
RewriteRule ^(.+) /cgi-bin/page.cgi?g=$1 [L]

Which I should be able to emulate using something like:

RewriteCond %{REQUEST_URI}
RewriteRule ^(.*) $1 [L]

I'm not sure exactly, I just want it to just goto the directory regularly if it exists, otherwise use the other two RewriteRules. I guess I don't know how to check for a directory.

- Jonathan
Quote Reply
Re: [jdgamble] Mod rewrite In reply to
Give this a try:
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Adrian
Quote Reply
Re: [brewt] Mod rewrite In reply to
Okay, I'm definately getting closer. If I use this:

Code:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*) $1 [L]
RewriteRule ^(.*) /cgi-bin/page.cgi?g=$1 [L]
RewriteRule ^/?$ /cgi-bin/page.cgi [L]


Then http://mydomain.com/New works, http://mydomain.com/New/date.html works, and it does load the css folder properly. However, http://mydomain.com/ does not load anything.

If I remove the [OR], then everything works EXCEPT loading the file (i.e. the css folder). If I switch the last two lines, everything works but the home page (in other works, no change). Most every other change I make looses some functionality, usually loading the css folder.

I wish I could group these rewrite rules in blocks; I'm not sure how it is not working and how it is working the way it is. I'm so close.

- Jonathan
Quote Reply
Re: [brewt] Mod rewrite In reply to
I got it. It's all about the order I put it in. This works:

Code:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /cgi-bin/page.cgi?g=$1 [L]
RewriteRule ^/?$ /cgi-bin/page.cgi [L]
RewriteRule ^(.*) $1 [L]


Thanks,

- Jonathan
Quote Reply
Re: [jdgamble] Mod rewrite In reply to
I don't think you need that last rewrite rule.

Adrian

Last edited by:

brewt: Sep 9, 2006, 4:11 PM
Quote Reply
Re: [brewt] Mod rewrite In reply to
Your right! Why tell the program to goto a directory when it will do it anyway!

So this works now:

Code:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /cgi-bin/page.cgi?g=$1 [L]
RewriteRule ^/?$ /cgi-bin/page.cgi [L]


Seems simple enough.

Thanks,

- Jonathan