+ Reply to Thread
Results 1 to 7 of 7

Thread: .htaccess selective redirecting

  1. #1
    Sharky's Avatar
    Sharky is offline Admiral Awesome Sharky will become famous soon enough
    Join Date
    Oct 2007
    Location
    Outside the USA
    Posts
    3,306

    .htaccess selective redirecting

    So... I'm trying to do something with .htaccess, and it won't work...

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx
    RewriteCond %{REQUEST_URI} $.jpg|.jpeg|.png|.gif
    RewriteRule ^(.*)$ http://sharkyonline.co.cc.nyud.net/-/$1 [R,L]
    </IfModule>

    I want it to check the user agent, if it's not CoralWebPrx, I want it to check the filetype, if it's jpg, jpeg, png, or gif, I want it to redirect it to a new URL on a different server. Now, it works without the REQUEST_URI line. WITH the REQUEST_URI line, it makes no difference if the rewrite block is there or not.

    Any ideas?
    The physics is theoretical but the fun is real.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: .htaccess selective redirecting

    Not that familiar with mod_rewrite regex syntax, but

    Code:
     
     
     
    RewriteCond %{REQUEST_URI} (.jpg|.jpeg|.png|.gif)$
    might work
    Nothing is always absolutely so.

  3. #3
    Sharky's Avatar
    Sharky is offline Admiral Awesome Sharky will become famous soon enough
    Join Date
    Oct 2007
    Location
    Outside the USA
    Posts
    3,306

    Re: .htaccess selective redirecting

    You, sir, are a legend. Thankyou.

    Any idea how to write an exclusion to make sure that a URL doesn't contain a certain character or string? eg., I have all my addon domains in public_html/_/<addon domain dir> . In short, I'd like to have a .htaccess in the /public_html directory that doesn't screw up all the addon domains.
    The physics is theoretical but the fun is real.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: .htaccess selective redirecting

    Quote Originally Posted by Sharky View Post
    You, sir, are a legend. Thankyou.

    Any idea how to write an exclusion to make sure that a URL doesn't contain a certain character or string? eg., I have all my addon domains in public_html/_/<addon domain dir> . In short, I'd like to have a .htaccess in the /public_html directory that doesn't screw up all the addon domains.
    You mean a additional rule to the original two so that image files for the addon domains do not get redirected along with those for the main domain?
    Nothing is always absolutely so.

  5. #5
    Sharky's Avatar
    Sharky is offline Admiral Awesome Sharky will become famous soon enough
    Join Date
    Oct 2007
    Location
    Outside the USA
    Posts
    3,306

    Re: .htaccess selective redirecting

    Precisely.
    The physics is theoretical but the fun is real.

  6. #6
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: .htaccess selective redirecting

    1. I am not 100% sure how they handle addon domains. From what I gather if you add sharkysworld.com to your account, the root directory for that domain is
    /public_html/_/sharkeysworld.com/
    Then I assume they use mod_rewrite to adjust the incoming urls.

    With those assumptions....

    RewriteCond %{HTTP_HOST} !(sharkeysworld\.com|sharkbait\.org|sharktank\.net ) [NC]
    RewriteCond %{REQUEST_URI} !(sharkeysworld\.com|sharkbait\.org|sharktank\.net )

    might do the trick. If the .htaccess contains rewrites that already map the addon domains to subdirectories, all you would need is the second line.
    Nothing is always absolutely so.

  7. #7
    Sharky's Avatar
    Sharky is offline Admiral Awesome Sharky will become famous soon enough
    Join Date
    Oct 2007
    Location
    Outside the USA
    Posts
    3,306

    Re: .htaccess selective redirecting

    Fantastic. It works!

    For anyone finding this via the searching, and who wants to use the CoralCDN to load images from their website (without interfering with addon domains), you can use this in your .htaccess file:

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !(domain2.com|domain3.com) [NC]
    RewriteCond %{REQUEST_URI} !(domain2.com|domain3.com) [NC]
    RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx [NC]
    RewriteCond %{REQUEST_URI} (.jpg|.jpeg|.png|.gif)$ [NC]
    RewriteRule ^(.*)$ http://domain1.com.nyud.net/$1 [R,L]
    </IfModule>

    Without the exclusions, addon domains that are located in a subdirectory of the main domain will be affected by the .htaccess. Eg., having your main domain as domain1.com and an addon domain of domain2.com , if you store the code in the .htaccess for domain1.com , visiting domain2.com will load images from domain1.com.nyud.net/sitesdir/domain2.com/file.jpeg .

    Credit to descalzo for correcting my attempts at filtering by file extension, and for coming up with the method for excluding addon domains.

    Thanks again!
    Last edited by Sharky; 09-19-2009 at 10:32 AM. Reason: [EDIT1: Added [CODE] tags.]
    The physics is theoretical but the fun is real.

+ Reply to Thread

Similar Threads

  1. Error redirecting parked domain - please help
    By gillapsfi in forum Free Hosting
    Replies: 0
    Last Post: 01-29-2009, 07:43 PM
  2. Se puede usar .htaccess????
    By rackfenix in forum Soporte
    Replies: 7
    Last Post: 10-02-2007, 07:03 PM
  3. default .htaccess
    By Fedlerner in forum Computers & Technology
    Replies: 9
    Last Post: 09-05-2007, 09:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers