Cannot get basic RewriteRule to work!
Cannot get basic RewriteRule to work!
am 22.07.2007 17:30:43 von dvader
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.
--
Crash
Re: Cannot get basic RewriteRule to work!
am 22.07.2007 20:18:21 von Paul Furman
"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
Re: Cannot get basic RewriteRule to work!
am 22.07.2007 20:37:38 von Paul Furman
Paul Furman wrote:
> 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.
OK here's a simple one:
RewriteRule ^?SC=go.php&DIR=(.)$ $1 [R]
the (.) is supposed to indicate "anything" like *
the $1 is supposed to replace that minus the ?SC=go.php&DIR=
I get this in the error log:
RewriteRule: cannot compile regular expression '^?SC=go.php&DIR=(.)$'
Now if it worked, that would take me to a folder which does not exist so
I'd also need the reverse to follow this rule without the [R] In this
case there is nothing left to search for short of a full list of all the
possible paths that might follow [?SC=go.php&DIR=]. One thing I could do
is look for the /1/ because this all happens under /1/ but I already set
this:
RewriteBase /1
so I'm not sure if I can do that.
--
Paul Furman Photography
http://www.edgehill.net/1
Bay Natives Nursery
http://www.baynatives.com
Re: Cannot get basic RewriteRule to work!
am 22.07.2007 20:48:18 von dvader
> You have my sympathy.
Thank you. I'll take anything I can get. :-)
> I'm not sure what you are trying to accomplish though.
Okay, some details. From my httpd.conf file:
DocumentRoot "L:/DataList"
AllowOverride All
Options FollowSymLinks ExecCGI
Order allow,deny
Allow from all
Alias /restricted "L:/restricted"
AllowOverride All
Options FollowSymLinks
Order allow,deny
Allow from all
..htaccess is in the L:\DataList directory with these two lines:
RewriteEngine on
RewriteRule ^/$ /restricted
What I want to do is redirect requests for the default file (index.html) in the
document root (/) to the defaul file in the virtual directory /restricted. I
have tried it with and without the filename, and with and without RewriteBase.
--
Crash
Re: Cannot get basic RewriteRule to work!
am 22.07.2007 21:25:17 von dvader
Got it, but I sure don't understand it. This works:
RewriteRule ^index\.html$ /restricted
--
Crash
Re: Cannot get basic RewriteRule to work!
am 23.07.2007 01:39:56 von Paul Furman
Paul Furman wrote:
> Paul Furman wrote:
>
>> 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.
>
>
> OK here's a simple one:
>
> RewriteRule ^?SC=go.php&DIR=(.)$ $1 [R]
>
> the (.) is supposed to indicate "anything" like *
PS I just spent a few hours getting some tutoring on this, the (.)
should be (.+) and what I wanted is not possible, I need to list the
destination folders behind the query in the url, there is no way to just
wipe it out. Fortunately there aren't that many top folders & I can make
everything below follow the top rules. Unfortunately, now I need to
change all my coding to absolute urls, ack what a nightmare. It's all
php generated though so maybe not too bad.
> the $1 is supposed to replace that minus the ?SC=go.php&DIR=
>
> I get this in the error log:
> RewriteRule: cannot compile regular expression '^?SC=go.php&DIR=(.)$'
>
> Now if it worked, that would take me to a folder which does not exist so
> I'd also need the reverse to follow this rule without the [R] In this
> case there is nothing left to search for short of a full list of all the
> possible paths that might follow [?SC=go.php&DIR=]. One thing I could do
> is look for the /1/ because this all happens under /1/ but I already set
> this:
> RewriteBase /1
> so I'm not sure if I can do that.
>
>
>
>
--
Paul Furman Photography
http://www.edgehill.net/1
Bay Natives Nursery
http://www.baynatives.com
Re: Cannot get basic RewriteRule to work!
am 23.07.2007 20:19:49 von Paul Furman
Paul Furman wrote:
> Paul Furman wrote:
>
>> Paul Furman wrote:
>>
>>> 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.
>>
>>
>>
>> OK here's a simple one:
>>
>> RewriteRule ^?SC=go.php&DIR=(.)$ $1 [R]
>>
>> the (.) is supposed to indicate "anything" like *
>
>
> PS I just spent a few hours getting some tutoring on this, the (.)
> should be (.+) and what I wanted is not possible, I need to list the
> destination folders behind the query in the url, there is no way to just
> wipe it out. Fortunately there aren't that many top folders & I can make
> everything below follow the top rules. Unfortunately, now I need to
> change all my coding to absolute urls, ack what a nightmare. It's all
> php generated though so maybe not too bad.
PPS it's not that bad, all I had to do was get rewriterules for the
first level of folders & the rest falls in place.
>> the $1 is supposed to replace that minus the ?SC=go.php&DIR=
>>
>> I get this in the error log:
>> RewriteRule: cannot compile regular expression '^?SC=go.php&DIR=(.)$'
>>
>> Now if it worked, that would take me to a folder which does not exist
>> so I'd also need the reverse to follow this rule without the [R] In
>> this case there is nothing left to search for short of a full list of
>> all the possible paths that might follow [?SC=go.php&DIR=]. One thing
>> I could do is look for the /1/ because this all happens under /1/ but
>> I already set this:
>> RewriteBase /1
>> so I'm not sure if I can do that.
>>
>>
>>
>>
>
>
--
Paul Furman Photography
http://www.edgehill.net/1
Bay Natives Nursery
http://www.baynatives.com