SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Need some htaccess URL rewriting help...

    I have the following in my .htaccess file (minus that "1.", which I have no idea why that was added because I used the code block to insert the htaccess code--which is what I thought I needed to do?):

    Code:
    1. RewriteEngine On RewriteBase / RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1 RewriteCond %{REMOTE_ADDR} !^149\.102\.45\.147 RewriteCond %{REMOTE_ADDR} !^149\.102\.45\.83 RewriteCond %{REQUEST_URI} !/projects/abc_wiki$ RewriteRule .* /projects/calendar.abc.edu [R=302,L] rewritecond %{http_host} ^localhost.abc.edu [nc] rewriteRule ^(.*)$ http://localhost:8080/www/projects/calendar.abc.edu/$1 [r=301,nc]
    I'm not sure how to exactly word this, so bear with me here...

    I need to make my browser forward localhost.calendar.edu to 127.0.0.1 where I have WAMP and UltiDev running to handle both PHP and ASP stuff. This, I have working... But how can I make all "localhost.calendar.edu" browser requests be forwarded to the sub-directory of "www/projects/calendar.abc.edu" and make that sub-directory appear to have localhost.calendar.edu as its domain name? So for example, if I'm on my workstation browsing to www/index.php, the domain name would probably be something like "http://localhost/index.php", but what I want to do is have "http://localhost.calendar.edu" when I'm browsing for "localhost.calendar.edu" from within www/projects/calendar.abc.edu. (I'm trying to set my sub-directory to use its own exclusive domain, but I'm not sure if this is being worded correctly to explain what I'm trying to do here.)

    In my HOSTS file, I have "localhost.calendar.edu" assigned to 127.0.0.1, so now whenever I travel to localhost.calendar.edu, I at least get forwarded to my www root. This is correct: I can see my domain in the address bar and everything is working. But now I need to do something with .htaccess. I think it's called a "rewrite" (and not a redirect) despite Firefox telling me that the redirect will never succeed--for reasons I can't understand yet. I think a problem to consider here with this is how Apache will offload the request into :8080, which is being handled by UltiDev (the ASP server I have running).

    (My understanding of .htaccess code / syntax isn't that great, so any input / insight into what I'm trying to do here is very appreciated.)

    Note: The reason I'm trying to do all this is because I'm working on some legacy ASP installations and I'm just trying to test for specific domain names in my scripts. I'm trying to build a file-level process to handle specific URL requests. I'm working on something IIS-related from a production environment that has forced us to resort to this approach due to how various virtual directories / bindings have been configured through IIS--which I despise, FWIW.

  2. #2
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry everyone, but I think I got it figured out (feel free to provide any additional insight if you want or if you see anything wrong with the following):

    Code:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
    RewriteCond %{REMOTE_ADDR} !^149\.102\.45\.147
    RewriteCond %{REMOTE_ADDR} !^149\.102\.45\.83
    RewriteCond %{REQUEST_URI} !/projects/abc_wiki$  
    
    RewriteCond %{HTTP_HOST} ^localhost.calendar.edu$
    RewriteCond %{REQUEST_URI} !^/projects/calendar.abc.edu/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /projects/calendar.abc.edu/$1
    RewriteCond %{HTTP_HOST} ^localhost.calendar.edu$
    RewriteRule ^(/)?$ projects/calendar.abc.edu/ [L]
    Btw, I use the first RewriteConds to redirect clients to an informational site I have setup on my localhost. I don't open up my entire computer to everyone (for obvious reasons) but it's nice to provide static information about things from time-to-time (which is what those are for--I needed to allow them to access that specific directory alone--which I hope isn't impaired now by what I've done with this sub-directory stuff).

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    W_22,

    If possible, I'd send your "visitors" to another link after their checks (OR use a Switch flag to circumvent the other code - use the digits for the number of RewriteRules to skip).

    Coding concerns (as usual):

    Code:
    RewriteEngine On
    RewriteBase /
    # WHY?
    RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
    RewriteCond %{REMOTE_ADDR} !^149\.102\.45\.147
    RewriteCond %{REMOTE_ADDR} !^149\.102\.45\.83
    RewriteCond %{REQUEST_URI} !/projects/abc_wiki$  
    # Will only match with Apache 1.x
    
    RewriteCond %{HTTP_HOST} ^localhost.calendar.edu$
    RewriteCond %{REQUEST_URI} !^/projects/calendar.abc.edu/
    Ditto
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /projects/calendar.abc.edu/$1
    RewriteCond %{HTTP_HOST} ^localhost.calendar.edu$
    RewriteRule ^(/)?$ projects/calendar.abc.edu/ [L]
    # What's this for? With the $, you're only looking at the DocumentRoot.
    Regards

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •