Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

(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
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2018-06-21 05:37 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.