Can Mod Rewrite do this??

Discussion in 'Apache' started by dwest, Feb 4, 2007.

  1. #1
    Can anyone tell me how to do the following using mod rewrite?

    I want to take any URL request containing "www.domainname.com" or "domainname.com" and replace "www.domainname.com" or "domainname.com" with "ip_address/~username".

    All the stuff in the URL before and after the replacement should remain intact.

    Thanks!
     
    dwest, Feb 4, 2007 IP
  2. oziman

    oziman Active Member

    Messages:
    199
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #2
    #Redirect domain/www.domain to you're ip
    RewriteCond %{HTTP_HOST} ^domainname.com
    RewriteRule ^(.*)$ http://ipaddress/~user/$1 [r=301,L]

    My regex is rusty, but this works on on of our sites.. Others, feel free to correct me. Above code will only work for domainname.com and not www, you can either add another one with www, or use a better regex.


     
    oziman, Feb 4, 2007 IP
  3. JRBHosting

    JRBHosting Peon

    Messages:
    121
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Your code looks right. I would have left out the RewriteCond, though, and just done:

    
    RewriteEngine On
    RewriteRule www.domain.com/(.*) http://ipaddress/~user/$1 [r=301,L] 
    RewriteRule domain.com/(.*) http://ipaddress/~user/$1 [r=301,L]
    
    Code (markup):
     
    JRBHosting, Feb 4, 2007 IP