View Single Post

  #2 (permalink)  
Old 07-22-2007
Paul Furman
 
Posts: n/a
Default Re: Cannot get basic RewriteRule to work!

"Crash" Dummy wrote:

> I am brand new to Apache, so be gentle.
>
> I am trying to redirect clients to a different directory using RewriteRule in a
> .htaccess file in the root directory. I have been doing it successfully using
> DirectoryIndex, but when I try to replace
>
> DirectoryIndex /restricted
>
> with
>
> RewriteEngine on
> RewriteRule ^/$ /restricted
>
> it doesn't work. It is as close to a "Hello, World!" operation for RewriteRule
> as you can get. What am I missing?
>
> I am using Apache 2.2.4 on W2K Pro. The mod_rewrite module is loaded.


You have my sympathy.

I'm not sure what you are trying to accomplish though.

There are a couple other settings that might not be correct. Assuming
you are using .htaccess, check that the http.conf says:
AllowOverride All
Options FollowSymLinks
Also I was starting from a subdirectory /1 so had to add this to my
..htaccess:
RewriteBase /1


Here's a couple 'hello world' solutions I got to work to prove the damn
thing is actually running:
RewriteRule ^old\.html$ new.html
RewriteRule ^old\.html$ new.html [R]
Create those files & simply typ "old" & "new" inside them. Notice how
the [R] rewrites the url in the address bar.

What I'm struggling with now is currently looking like this:
RewriteRule ^.Gallery$ ?SC=go.php&DIR=0_gallery [R]

What I want it to do is allow me to type the url:
Gallery
and have it land at:
?SC=go.php&DIR=0_gallery

I've tried a million things and the regex is I think what's stumping me.
Here's a little simpler one: I'd like to be able to apply a simple
freaking wildcard for
?SC=go.php&DIR=* [note my star wildcard at the end]
?SC=go.php&DIR=(.*)?????????
?SC=go.php&DIR=(.)??????????
????????????????????????????

then for rewrite, I don't know how to tell it to replace that gunk with
nothing. How do indicate "nothing"? do I need to create a little token
in there so there's something to talk about & convert to
[?SC=go.php&DIR=]? And I think I want to go both ways so if people type
the long url it changes to the new short one & if they type the short
one, it translates into the real long one on the server.

I'm exasperated & making almost no progress. There is no such thing as
'regex for idiots' as far as I can tell.

--
Paul Furman Photography
http://www.edgehill.net/1
Bay Natives Nursery
http://www.baynatives.com