SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Redirecting a URL to a subdomain regardless of Virtual Domain

    I'm trying to redirect http://www.anydomain.com/rc to http://webmail.anydomain.com

    It needs to work on all virtual domains.

    This is what I have so far
    Code:
    RewriteCond %{REQUEST_URI} ^/rc(/?)$ [NC]
    RewriteRule ^(.*)$ http://webmail.%{HTTP_HOST} [R=302,L]
    This works for http://anydomain.com/rc which is correctly rewritten to http://webmail.anydomain.com

    but it doesn't work for http://www.anydomain.com/rc which becomes http://www.webmail.anydomain.com

    Can anyone show me how to do this please?

    Kind regards,

    Peter

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Code:
    RewriteCond %{REQUEST_URI} ^/rc [NC]
    RewriteRule .? http://webmail.hardcode-the-domain.tld [R=302,L]
    That should work if you actually put the domain instead of using HTTP_HOST to fill it in. (HTTP_HOST will contain the www subdomain)
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True, but that's not going to work in my global httpd.conf for all virtual subdomains.

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Lets see you config (httpd.conf) for these virtual domains.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is one of them. They each have their own .conf files

    Code:
    <VirtualHost *:80>
            ServerName www.domain1.com
            ServerAlias domain1.com
            DocumentRoot /var/www/html/www/public
            ScriptAlias /cgi-bin/ /var/www/html/www/public/cgi-bin/
    
            CustomLog /var/log/httpd/sites/www.bytes bytes
            CustomLog /var/log/httpd/sites/www.log combined
            ErrorLog /var/log/httpd/sites/www.error.log
    
            <Directory /var/www/html/www/public>
                    Options +Includes -Indexes
            </Directory>
    </VirtualHost>
    I'm hoping to put the solution in the main httpd.conf though.

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Code:
    RewriteEngine on
    
    
    # Removing "www" subdomain.
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
    
    
    RewriteCond %{REQUEST_URI} ^/rc [NC]
    RewriteRule .? http://webmail.%{HTTP_HOST} [R=302,L]
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •