SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    redirect any webpage access to one page

    hello,

    i've got this on a site which is a single page site -- a site coming soon page -- so any page access results in seeing the single home page. the single home page has some images on hense the need to let those requests through.
    Code:
    RewriteRule ^(.+\.jpg)$ $1 [L]
    RewriteRule ^(.+\.png)$ $1 [L]
    RewriteRule ^(.+\.gif)$ $1 [L]
    RewriteRule ^(.+\.ico)$ $1 [L]
    RewriteRule ^.+$ index.html [L]
    how can i do what that's doing but instead of rewrite, redirect to the home page?

    so i want any webpage access like mysite.com/blahblah to get redirected to mysite.com -- the home page, and for the image accesses to still be ok.

    any ideas?

    thanks.

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

    Quote Originally Posted by johnyboy View Post
    hello,

    i've got this on a site which is a single page site -- a site coming soon page -- so any page access results in seeing the single home page. the single home page has some images on hense the need to let those requests through.
    Code:
    RewriteRule ^(.+\.jpg)$ $1 [L]
    RewriteRule ^(.+\.png)$ $1 [L]
    RewriteRule ^(.+\.gif)$ $1 [L]
    RewriteRule ^(.+\.ico)$ $1 [L]
    RewriteRule ^.+$ index.html [L]
    how can i do what that's doing but instead of rewrite, redirect to the home page?

    so i want any webpage access like mysite.com/blahblah to get redirected to mysite.com -- the home page, and for the image accesses to still be ok.
    That was a mouthful just to get to the real question (and all before that showed a lack of understanding of mod_rewrite which we'll quickly correct).

    To redirect EVERYTHING (except images) to the index.html page, create the exclusion then redirect EVERYTHING:
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|ico)$ [NC]
    # don't forget that EVERYTHING includes index.html
    # so you need to exclude that, too!
    RewriteCond %{REQUEST_URI} !^/?index\.html$
    # now that the exclusions are in place
    RewriteRule .? index.html [R=301,L]
    For more information, have a look at the tutorial Article in my signature - but we've been that route before, haven't we?

    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
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    your suggestion displays the wrong url, a long url in the browser's address bar, so it's redirecting to an incorrect address, like so:
    http://xxxxx.com/home/users/xxxxx/html/xxxxx/index.html
    and results in an infinite loop.

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

    Your Apache has a problem - it should NEVER put the physical address in the URL. Restart Apache (or have your host do it).

    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
  •