Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

(OT) mod_rewrite anyone?

by mrc (Sexton)
on Sep 26, 2009 at 10:57 UTC ( #797673=perlquestion: print w/replies, xml ) Need Help??
mrc has asked for the wisdom of the Perl Monks concerning the following question:

I'm using mod_rewrite to virtually map to a local path.


RewriteEngine On RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+\.[^.]+)$ RewriteRule ^(.*) http://%1$1 [R,L] VirtualDocumentRoot /home/user/%0
RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+\.[^.]+)$ will redirect to, but I want the reverse. redirected to and 'www' url to remain unchanged.
Changing the rule to RewriteRule ^(.*) http://www\.%1$1 [R,L] will broke entire configuration. I have also tried to modify RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+\.[^.]+)$ in many ways, but I don't know how to solve it.
Any help would be greatly appreciated. Thank you!!

Replies are listed 'Best First'.
Re: (OT) mod_rewrite anyone?
by merlyn (Sage) on Sep 26, 2009 at 16:02 UTC
    Why are you still using mod_rewrite? I gave that up the moment I discovered I could use mod_perl to do it far easier and better, and with a real language, instead of a language involving yet another arcane syntax.

    Just set up a PerlTransHandler that modifies the right strings, and you're done.

    -- Randal L. Schwartz, Perl hacker

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

      Thanks for suggestion.
Re: (OT) mod_rewrite anyone?
by clinton (Priest) on Sep 26, 2009 at 11:02 UTC

    Firstly, this has nothing to do with Perl.

    Secondly, if you look at the docs for apache, you will find a link to the URL rewriting guide, and the second entry Canonical Hostnames explains how you would achieve this.

      ...and the second entry Canonical Hostnames explains how you would achieve this.
      Yes but I need a wildcard. I tried something like
      RewriteCond %{HTTP_HOST} !^www\.%1 [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/?(.*) http://www.%1/$1 [L,R,NE]
      but not working. These rules are so hard :(
      Firstly, this has nothing to do with Perl.
      Hmm :( Regexes are very similar to perl.
        Nice try ;)
Re: (OT) mod_rewrite anyone?
by moritz (Cardinal) on Sep 26, 2009 at 11:02 UTC
    RewriteCond %{HTTP_HOST} !^www RewriteRule ^(.*) http://www.%{HTTP_HOST}$1 [R,L]

    (Don't know if you can interpolate these variables in URLs)

    Perl 6 - links to (nearly) everything that is Perl 6.
      Not working, sadly.
        It would help if you were more specific.
        Perl 6 - links to (nearly) everything that is Perl 6.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://797673]
Approved by AnomalousMonk
[marioroy]: CORE::wait can block if another process reaps a worker from another class. MCE::Hobo takes care of that and transparently.
[Discipulus]: thanks choroba i'll update my answer
[Lady_Aleena]: Hello Discipulus, Corion, choroba, and marioroy...
[Corion]: Hi Lady_Aleena!
[Lady_Aleena]: marioroy, are you also writing a Meditation for this?
choroba o/
Discipulus adds tozzetti alle mandorle to the platter on the sideboard.
Lady_Aleena was checking #cbstream and saw the big announcement.
[marioroy]: Tie::IxHash can be shared. Also similar modules. I cannot wait to post a solution sharing Tie::File and iterating among workers.
[marioroy]: Lady_Aleena Yes, will post something with all the new features. Parallel with few lines of code.

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2017-05-26 08:50 GMT
Find Nodes?
    Voting Booth?