SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)

    htaccess code for maintenance page redirect

    I set up a maintenance page that I could enable through an htaccess file. The html file is located in a folder called "maintenance".


    The html file has some images in it. However, visitors to the page see no images, even though I added a `RewriteCond` line to (theoretically) allow them.


    If I try to visit the URL of an image file in the browser directly, it redirects to the maintenance.htm page. I do not want image files to be redirected.


    Am I missing something?


    Code:
        #RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
        #RewriteCond %{REMOTE_ADDR} !^111.111.111.111$
        RewriteCond %{REQUEST_URI} !/maintenance/maintenance\.htm$ [NC]
        RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|png|gif|css|ico)$ [NC]
        RewriteRule ^(.*)$ /maintenance/maintenance.htm [R=302,L]
    Last edited by Force Flow; Dec 6, 2012 at 22:15.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  2. #2
    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)
    FF,

    Aw, if you are redirecting to the maintenance folder, chances are that you're changing the folder level of the request which is upsetting the relative links which are looking relative to the requested URI. I'd tell others to read the tutorial but, since I brought you onboard, either use the <base> tag (with the actual URI) OR links relative to the original request (not the maintenance folder) OR use absolute internal links. It would be easiest for your single file to use the <base> tag but the absolute internal links are awfully handy, too.

    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

  3. #3
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by dklynn View Post
    Aw, if you are redirecting to the maintenance folder, chances are that you're changing the folder level of the request which is upsetting the relative links which are looking relative to the requested URI. I'd tell others to read the tutorial but, since I brought you onboard, either use the <base> tag (with the actual URI) OR links relative to the original request (not the maintenance folder) OR use absolute internal links. It would be easiest for your single file to use the <base> tag but the absolute internal links are awfully handy, too.
    All image files from anywhere on the website are redirected to the maintenance.htm page. It's not just a relative link issue on that particular page.

    For example, if I try to visit http://mydomain.com/myimage.jpg or http://mydomain.com/maintenance/construction.jpg, the images get redirected to http://mydomain.com/maintenance/maintenance.htm
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  4. #4
    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)
    FF,

    Code:
        #RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
        #RewriteCond %{REMOTE_ADDR} !^111.111.111.111$
        RewriteCond %{REQUEST_URI} !/maintenance/maintenance\.htm$ [NC]
        RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|png|gif|css|ico)$ [NC]
        RewriteRule ^(.*)$ /maintenance/maintenance.htm [R=302,L]
    Your code will NOT redirect .jpg, .jpeg,.png, .gif, .css or .ico as specified by your second (active) RewriteCond. Therefore, there must be conflicting code elsewhere in your .htaccess so I have to request that you either post it here or PM me if you need to keep it private.

    Whoops, remove the leading / in your first (active) RewriteCond as that requires Apache 1.x. If that doesn't resolve your issue, then Go Back one paragraph.

    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
  •