OT: Rewrite question

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

OT: Rewrite question

Jussi Hirvi-2
Help needed - googling only gets me more confused.

I have a rewrite rule which allows me to use "nice" URLs like

http://www.mysite.fi/mypage

The rule set is like this:
     # Rewrite URLs of the form 'x' to the form 'index.html?p=x'.
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_URI} !=/favicon.ico
     RewriteRule ^(.*)$ index.html?p=$1 [L,QSA]

Now, I would like to build another, independent site into a
subdirectory. So this:
        http://www.mysite.fi/mysiteroot/mypage
should be rewritten to:
        http://www.mysite.fi/mysiteroot/index.html?p=mypage
without disturbing the main site at the domain root.

The problem is how to handle the subdirectory name in the rewrite script.

Thanks in advance,
Jussi
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: OT: Rewrite question

stevepiercy
Try adding another block of directives above the former, so that
the request passes through the blocks in order until one block
is completely satisfied.  The more specific filter should be first.

      # Rewrite URLs of the form 'x' to the form 'index.html?p=x'.
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} ^/mysiteroot/mypage
      RewriteCond %{REQUEST_URI} !=/favicon.ico
      RewriteRule ^(.*)$ /mysiteroot/index.html?p=$1 [L,QSA]

Untested, shooting from the hip, and probably wrong, but that's
the idear.

--steve


On 11/22/11 at 5:30 PM, [hidden email] (Jussi Hirvi) pronounced:

>Help needed - googling only gets me more confused.
>
>I have a rewrite rule which allows me to use "nice" URLs like
>
>http://www.mysite.fi/mypage
>
>The rule set is like this:
># Rewrite URLs of the form 'x' to the form 'index.html?p=x'.
>RewriteCond %{REQUEST_FILENAME} !-f
>RewriteCond %{REQUEST_FILENAME} !-d
>RewriteCond %{REQUEST_URI} !=/favicon.ico
>RewriteRule ^(.*)$ index.html?p=$1 [L,QSA]
>
>Now, I would like to build another, independent site into a subdirectory. So this:
>http://www.mysite.fi/mysiteroot/mypage
>should be rewritten to:
>http://www.mysite.fi/mysiteroot/index.html?p=mypage
>without disturbing the main site at the domain root.
>
>The problem is how to handle the subdirectory name in the rewrite script.
>
>Thanks in advance,
>Jussi
>#############################################################
>This message is sent to you because you are subscribed to
>the mailing list Lasso
>[hidden email]
>To unsubscribe, E-mail to: <[hidden email]>
>Send administrative queries to  <[hidden email]>

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: OT: Rewrite question

Eric Knibbe
To which I would add: use the % syntax in the RewriteRule to grab a bracketed value from the previous RewriteCond.

So, your full ruleset would probably look like:

# Rewrite URLs of the form 'x' to the form 'index.html?p=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !favicon.ico
RewriteCond %{REQUEST_URI} ^/mysiteroot/(.*)
RewriteRule ^ /mysiteroot/index.html?p=%1 [L,NC,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !favicon.ico
RewriteRule ^(.*)$ index.html?p=$1 [L,NC,QSA]

Rewriting to handle an arbitrary variety of subdirectories is left as an exercise to the reader.
‐‐‐‐‐‐‐‐‐‐✂‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Eric3
 

On 2011-11-22, at 12:37 PM, Steve Piercy - Web Site Builder wrote:

> Try adding another block of directives above the former, so that the request passes through the blocks in order until one block is completely satisfied.  The more specific filter should be first.
>
>     # Rewrite URLs of the form 'x' to the form 'index.html?p=x'.
>     RewriteCond %{REQUEST_FILENAME} !-f
>     RewriteCond %{REQUEST_FILENAME} !-d
>     RewriteCond %{REQUEST_URI} ^/mysiteroot/mypage
>     RewriteCond %{REQUEST_URI} !=/favicon.ico
>     RewriteRule ^(.*)$ /mysiteroot/index.html?p=$1 [L,QSA]
>
> Untested, shooting from the hip, and probably wrong, but that's the idear.
>
> --steve
>
>
> On 11/22/11 at 5:30 PM, [hidden email] (Jussi Hirvi) pronounced:
>
>> Help needed - googling only gets me more confused.
>>
>> I have a rewrite rule which allows me to use "nice" URLs like
>>
>> http://www.mysite.fi/mypage
>>
>> The rule set is like this:
>> # Rewrite URLs of the form 'x' to the form 'index.html?p=x'.
>> RewriteCond %{REQUEST_FILENAME} !-f
>> RewriteCond %{REQUEST_FILENAME} !-d
>> RewriteCond %{REQUEST_URI} !=/favicon.ico
>> RewriteRule ^(.*)$ index.html?p=$1 [L,QSA]
>>
>> Now, I would like to build another, independent site into a subdirectory. So this:
>> http://www.mysite.fi/mysiteroot/mypage
>> should be rewritten to:
>> http://www.mysite.fi/mysiteroot/index.html?p=mypage
>> without disturbing the main site at the domain root.
>>
>> The problem is how to handle the subdirectory name in the rewrite script.
>>
>> Thanks in advance,
>> Jussi
>> #############################################################
>> This message is sent to you because you are subscribed to
>> the mailing list Lasso
>> [hidden email]
>> To unsubscribe, E-mail to: <[hidden email]>
>> Send administrative queries to  <[hidden email]>
>
> -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
> Steve Piercy               Web Site Builder               Soquel, CA
> <[hidden email]>                  <http://www.StevePiercy.com/>
>
> #############################################################
> This message is sent to you because you are subscribed to
> the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: OT: Rewrite question

Brad Lindsay-2
On Nov 22, 2011, at 1:45 PM, Eric Knibbe wrote:

> To which I would add: use the % syntax in the RewriteRule to grab a bracketed value from the previous RewriteCond.

I'm pretty sure it's '$' and not '%'


> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteCond %{REQUEST_FILENAME} !favicon.ico
> RewriteRule ^(.*)$ index.html?p=$1 [L,NC,QSA]
>
> Rewriting to handle an arbitrary variety of subdirectories is left as an exercise to the reader.

How's this?


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !favicon.ico
RewriteCond %{REQUEST_URI} ^/(dir1|dir2|dir3)/(.*)
RewriteRule ^ /$1/index.html?p=$2 [L,NC,QSA]

Brad


#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: OT: Rewrite question

Jussi Hirvi-2
Thank you all for tips. I will test them tomorrow Helsinki time.
- Jussi
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: OT: Rewrite question

Eric Knibbe
In reply to this post by Brad Lindsay-2
On 2011-11-22, at 2:43 PM, Brad Lindsay wrote:

>> To which I would add: use the % syntax in the RewriteRule to grab a bracketed value from the previous RewriteCond.
>
> I'm pretty sure it's '$' and not '%'

Actually, the $1, $2, etc. variables refer to paren groups in the pattern part of the RewriteRule, while %1, %2, etc. variables refer to paren groups in the condition part of the preceding RewriteCond.

More info: <http://httpd.apache.org/docs/2.2/rewrite/intro.html#rewritecond>
‐‐‐‐‐‐‐‐‐‐✂‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Eric3
 


#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: OT: Rewrite question

Brad Lindsay-2
On Nov 22, 2011, at 4:26 PM, Eric Knibbe wrote:

> On 2011-11-22, at 2:43 PM, Brad Lindsay wrote:
>
>>> To which I would add: use the % syntax in the RewriteRule to grab a bracketed value from the previous RewriteCond.
>>
>> I'm pretty sure it's '$' and not '%'
>
> Actually, the $1, $2, etc. variables refer to paren groups in the pattern part of the RewriteRule, while %1, %2, etc. variables refer to paren groups in the condition part of the preceding RewriteCond.
>
> More info: <http://httpd.apache.org/docs/2.2/rewrite/intro.html#rewritecond>
> ‐‐‐‐‐‐‐‐‐‐✂‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐

Nice, thanks!

Brad
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: OT: Rewrite question

Jussi Hirvi-2
In reply to this post by Eric Knibbe
On 22.11.2011 20.45, Eric Knibbe wrote:

> So, your full ruleset would probably look like:
>
> # Rewrite URLs of the form 'x' to the form 'index.html?p=x'.
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteCond %{REQUEST_FILENAME} !favicon.ico
> RewriteCond %{REQUEST_URI} ^/mysiteroot/(.*)
> RewriteRule ^ /mysiteroot/index.html?p=%1 [L,NC,QSA]
>
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteCond %{REQUEST_FILENAME} !favicon.ico
> RewriteRule ^(.*)$ index.html?p=$1 [L,NC,QSA]
>
> Rewriting to handle an arbitrary variety of subdirectories is left as an exercise to the reader.

Thanks, I got it working on that principle. Here's the result for an
arbitrary subdir name:

     # Rewrite URLs of the form 'x' to the form 'index.html?p=x'.

     # First handle possible subdirs
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME} !favicon.ico
     RewriteCond %{REQUEST_URI} ^/(.*)/(.*)
     RewriteRule ^ /%1/index.html?p=%2 [L,NC,QSA]

     # Then the domain root level
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_URI} !=/favicon.ico
     RewriteRule ^(.*)$ index.html?p=$1 [L,QSA]

It took me a while to find out that the space after ^ in

 >    RewriteRule ^ /%1/index.html?p=%2 [L,NC,QSA]

... is meaningful.

Regards,
Jussi
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>