Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

(OT) mod_rewrite anyone?

by mrc (Sexton)
on Sep 26, 2009 at 10:57 UTC ( [id://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.

path:
/home/user/subdomain.domain.com/

Rules:
RewriteEngine On RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+\.[^.]+)$ RewriteRule ^(.*) http://%1$1 [R,L] VirtualDocumentRoot /home/user/%0
RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+\.[^.]+)$ will redirect http://www.subdomain.domain.com to http://subdomain.domain.com, but I want the reverse. http://subdomain.domain.com redirected to http://www.subdomain.domain.com 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.

    Clint
      ...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 :(
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: (OT) mod_rewrite anyone?
by moritz (Cardinal) on Sep 26, 2009 at 11:02 UTC
    Maybe
    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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://797673]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-18 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found