1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to redirect all pages to one page?

Discussion in 'Apache' started by explorer, Aug 20, 2005.

  1. #1
    I'm hoping to redirect visits to any page in an old directory to the index page of a new directory.

    In other words, redirect:

    http://www.domain.com/facts/*.*

    to

    http://www.domain.com/newfacts/

    Is this possible? If so, how could I do it?

    Thank you.


    p.s. In my .htaccess I currently have:
    
    RedirectPermanent /facts/     http://www.domain.com/newfacts/ 
    
    Code (markup):
    but this only redirects the index page.
     
    explorer, Aug 20, 2005 IP
  2. Willy

    Willy Peon

    Messages:
    281
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Put the following in your .htaccess:

    
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.domain\.com$
    RewriteRule ^facts/(.*)$ http://www.domain.com/newfacts/ [R=permanent,L]
    
    Code (markup):
    See the URL Rewriting Guide and the mod_rewrite Reference Guide for all your rewriting needs! :)
     
    Willy, Aug 20, 2005 IP
  3. GTech

    GTech Rob Jones for President!

    Messages:
    15,836
    Likes Received:
    571
    Best Answers:
    0
    Trophy Points:
    0
    #3
    GTech, Aug 20, 2005 IP
  4. fryman

    fryman Kiss my rep

    Messages:
    9,604
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    370
    #4
    fryman, Aug 20, 2005 IP
  5. ResaleBroker

    ResaleBroker Active Member

    Messages:
    1,665
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    90
    #5
    RewriteRule ^index(.*)$ http://www.domain.com/forums/ [L,R=301]
     
    ResaleBroker, Aug 20, 2005 IP
  6. Willy

    Willy Peon

    Messages:
    281
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Willy, Aug 20, 2005 IP
  7. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #7
    RedirectPermanent *will* do just that. Don't use mod-rewrite unless you have to - it's slower than using plain redirect. PM me the URL and I will tell you what's wrong with the response.

    J.D.
     
    J.D., Aug 20, 2005 IP
  8. Willy

    Willy Peon

    Messages:
    281
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I was intrigued by this and checked the docs: it indeed seems that, for instance, a directive "Redirect /facts http://domain.com/newfacts" will work so that if the client requests http://domain.com/facts/foo.txt, it'll be told to access http://domain.com/newfacts/foo.txt instead. However, I believe the original poster wanted a redirect to, essentially, http://domain.com/newfacts/ for all the original URLs.

    The RedirectMatch directive might provide functionality equivalent to my earlier mod_rewrite example, though. OTOH, the docs aren't clear whether it supports permanent (301) redirections, which the mod_rewrite will accomplish.
     
    Willy, Aug 20, 2005 IP
  9. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You are absolutely correct. My bad :eek: Mod-rewrite is definitely the way to go here.

    J.D.
     
    J.D., Aug 20, 2005 IP
  10. explorer

    explorer Well-Known Member

    Messages:
    463
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    110
    #10
    Thanks for your help guys - very much appreciated. :)
     
    explorer, Aug 27, 2005 IP
  11. miealex

    miealex Active Member

    Messages:
    65
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #11
    I have a question too after reading and trying to apply a redirect in .htaccess :mad:

    How do I redirect all incoming requests for
    domain.ro/whatever.... (domain.ro/whatever.fileextension or domain.ro/whatever/whatsoever.html) to domain.ro ?

    So basically all url requests should point to domain.ro
     
    miealex, Jun 19, 2007 IP
  12. miealex

    miealex Active Member

    Messages:
    65
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #12
    I managed to do it :) For anyone who comes here and wants to know, too, here it is:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
    
    RewriteRule \/.+ / [L,R]
    Code (markup):
     
    miealex, Jun 19, 2007 IP
  13. itmontreal.ca

    itmontreal.ca Peon

    Messages:
    13
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Hello,
    I thought this might be helpful for some people. I needed to redirect the contents of a complete folder to our main site. And here is how I achieved this:

    redirectMatch 301 ^/drupal/ http://www.itmontreal.ca

    Best regards,
    http://www.itmontreal.ca
     
    itmontreal.ca, Aug 15, 2009 IP
  14. 4spark

    4spark Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #14
    and i needed the whole domain, so i just removed the folder name and trailing slash. this redirects all urls in the old domain to the home page of the new site. not the best for seo but no time.

    redirectMatch 301 ^/ http://www.vermont-web-design.com
     
    4spark, Aug 30, 2010 IP
  15. audioholic

    audioholic Member

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #15
    Hi,

    I need to redirect all users either to the main domain or any .htm files inside that domain to a new domain's homepage. The redirectMatch 301 rule works just fine for this.

    But, there's a folder called 'FTP' inside the public_html directory. I want users to still be able to access this folder but other URL requests should be redirected. How do I achieve this?

    Any help would be greatly appreciated.

    Thanks,
    Sudarshan
     
    audioholic, Dec 16, 2010 IP
  16. gopkris2000

    gopkris2000 Peon

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    open your FTP directory index.php file and put this code to redirect another location.

    <?php
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: http://www.new-url.com" );
    ?>
     
    gopkris2000, Dec 16, 2010 IP
  17. Dan277

    Dan277 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    I was stuck on this exact same problem. Most solutions work, but not perfectly. I wanted it to work with all files on the domain, even ones that don't exist, and to not transfer the filename to the new location. Here is my code:

    ErrorDocument 404 /404.php
    RedirectMatch 301 ^/$ http://www.danspoker.com/rakeback.html

    In 404.php:
    <?
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: http://www.danspoker.com/rakeback.html" );
    ?>
     
    Dan277, Oct 25, 2011 IP
  18. altafali

    altafali Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    can you please help me on this redirect problem

    installed forum software in forums directory

    and linked subdomian to it working very well but when user type domain.com/forums/ it will not redirect to subdomain

    how can i fix that

    http://asf-mobiles.com
     
    altafali, Jul 22, 2012 IP
  19. mccomf

    mccomf Active Member

    Messages:
    517
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #19
    Thanks Dan277 . I was looking for this one for a while.Great to be able to redirect 404 pages to any page I like and not only to the home page.

     
    mccomf, Sep 14, 2012 IP
  20. Guruparthi

    Guruparthi Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #20
    RewriteRule ^facts/(.*)$ /newfacts [R,L]
     
    Guruparthi, Jun 19, 2014 IP