Simple Apache Redirects... I'm having a brain freeze.

Discussion in 'Apache' started by lpxxfaintxx, Jun 29, 2008.

  1. #1
    I want to redirect everything from domain1.com/directory/* to domain2.com/*. For example, domain1.com/directory/file2.ext would redirect to domain2.com/file2.ext.

    How would I go about accomplishing this? It seems so easy, yet I can't figure it out.
     
    lpxxfaintxx, Jun 29, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Something like:

    
    RewriteEngine On
    RewriteRule directory/(.*)$ http://www.domain2.com/$1 [R]
    
    Code (markup):
    That should get you going :) This needs to be placed in the root of domain1.com
     
    jayshah, Jun 29, 2008 IP
    lpxxfaintxx likes this.
  3. IGiveMoney

    IGiveMoney Peon

    Messages:
    116
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thats what i use on my personal apache server to assist me with some redirections

    great feature!
     
    IGiveMoney, Jun 29, 2008 IP
  4. lpxxfaintxx

    lpxxfaintxx Peon

    Messages:
    422
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the help! However, it's not working for some odd reason.

    I have placed the following on ZuneBoards.com:

    RewriteEngine On
    RewriteRule tv/(.*)$ http://www.vidsforzune.com/$1 [R]
    Code (markup):
    I want everything from ZuneBoards.com/tv/whatever.ext to go to VidsForZune.com/whatever.ext. Did I set it up correctly?


    Thanks mate!
     
    lpxxfaintxx, Jun 29, 2008 IP
  5. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #5
    That's correct. I just tested my code, with this:

    RewriteEngine On
    RewriteRule pastebin/(.*)$ http://$1.pastebin.com/ [R]
    
    Code (markup):
    So anything to http://www.mysite.com/pastebin/whatever becomes http://whatever.pastebin.com/.

    As a check, can you add:

    deny from all
    Code (markup):
    to the beginning of your .htaccess file, and refresh your site. If it still works, your host is ignoring your .htaccess file, if you get "Forbidden", remove the line and let me know.

    Jay
     
    jayshah, Jun 30, 2008 IP
  6. lpxxfaintxx

    lpxxfaintxx Peon

    Messages:
    422
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That's odd. I do get "Forbidden" so I do know the server is not ignoring the .htaccess. Maybe I should have mentioned this earlier, but my .htaccess already had things on it. Perhaps somethings cancelling something out? Anyways, heres the full file:

    
    RewriteEngine on
    RewriteRule tv/(.*)$ http://www.vidsforzune.com/$1 [R]
    
    
    Options +FollowSymLinks
    
    RewriteRule ^([^/]{2}_[^/]{2})/(.*)$ /components/com_jtranspro/index2.php?option=com_jtranspro&no_html=1 [L]
    
    RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$  [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php
    OpenSEF, 404_SEF, 404SEFx, SEF Advance, etc
    
    #RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] 		##optional - see notes##
    #RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$  [NC]
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule (.*) index.php
    
    
    ########## Begin - Rewrite rules to block out some common exploits
    ## If you experience problems on your site block out the operations listed below
    ## This attempts to block the most common type of exploit `attempts` to Joomla!
    #
    # Block out any script trying to set a mosConfig value through the URL
    RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
    # Block out any script trying to base64_encode crap to send via URL
    RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
    # Block out any script that includes a <script> tag in URL
    RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
    # Block out any script trying to set a PHP GLOBALS variable via URL
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    # Block out any script trying to modify a _REQUEST variable via URL
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    # Send all blocked request to homepage with 403 Forbidden error!
    RewriteRule ^(.*)$ index.php [F,L]
    #
    ########## End - Rewrite rules to block out some common exploitsRewriteCond %{HTTP_REFERER} !^http://aggressivegamers.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://aggressivegamers.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://b3ar.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://b3ar.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://forumbusinessblog.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://forumbusinessblog.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.aggressivegamers.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.aggressivegamers.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.b3ar.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.b3ar.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.forumbusinessblog.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.forumbusinessblog.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.socialsuccessnow.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.socialsuccessnow.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.zunetv.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.zunetv.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://zunetv.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://zunetv.zuneboards.com$      [NC]
    RewriteRule .*\.([^/]{2}_[^/]{2})$ - [F,NC]
    
    
    
    
    
    Code (markup):

    Thanks again
     
    lpxxfaintxx, Jun 30, 2008 IP
  7. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Hello,

    Yes, a conflict existed.

    Possibly:

    RewriteEngine on
    RewriteRule tv/(.*)$ http://www.vidsforzune.com/$1 [R,L]
    
    Options +FollowSymLinks
    
    RewriteRule ^([^/]{2}_[^/]{2})/(.*)$ /components/com_jtranspro/index2.php?option=com_jtranspro&no_html=1 [L]
    
    RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$  [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php
    
    #OpenSEF, 404_SEF, 404SEFx, SEF Advance, etc
    
    #RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR]            ##optional - see notes##
    #RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$  [NC]
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule (.*) index.php
    
    
    ########## Begin - Rewrite rules to block out some common exploits
    ## If you experience problems on your site block out the operations listed below
    ## This attempts to block the most common type of exploit `attempts` to Joomla!
    #
    # Block out any script trying to set a mosConfig value through the URL
    RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
    # Block out any script trying to base64_encode crap to send via URL
    RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
    # Block out any script that includes a <script> tag in URL
    RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
    # Block out any script trying to set a PHP GLOBALS variable via URL
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    # Block out any script trying to modify a _REQUEST variable via URL
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    # Send all blocked request to homepage with 403 Forbidden error!
    RewriteRule ^(.*)$ index.php [F,L]
    #
    ########## End - Rewrite rules to block out some common exploitsRewriteCond %{HTTP_REFERER} !^http://aggressivegamers.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://aggressivegamers.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://b3ar.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://b3ar.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://forumbusinessblog.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://forumbusinessblog.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.aggressivegamers.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.aggressivegamers.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.b3ar.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.b3ar.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.forumbusinessblog.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.forumbusinessblog.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.socialsuccessnow.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.socialsuccessnow.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.zunetv.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.zunetv.zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://zuneboards.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://zunetv.zuneboards.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://zunetv.zuneboards.com$      [NC]
    RewriteRule .*\.([^/]{2}_[^/]{2})$ - [F,NC]
    
    Code (markup):
    Backup your original first. Also, yours had an error as the line
    OpenSEF, 404_SEF, 404SEFx, SEF Advance, etc
    Code (markup):
    Wasn't commented out :)

    Jay
     
    jayshah, Jun 30, 2008 IP
  8. lpxxfaintxx

    lpxxfaintxx Peon

    Messages:
    422
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks, however, it still does not redirect at all. Very odd... =/
     
    lpxxfaintxx, Jun 30, 2008 IP
  9. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #9
    :confused: I tested it, and it works fine :eek:

    Do the other rules still work?

    Jay
     
    jayshah, Jul 1, 2008 IP
  10. lpxxfaintxx

    lpxxfaintxx Peon

    Messages:
    422
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Yup, all the others are working fine. =/ I have no idea what's wrong, or what could be causing this.
     
    lpxxfaintxx, Jul 2, 2008 IP