htaccess redirect all pages to single page

前端 未结 5 779
野性不改
野性不改 2020-11-30 01:20

I want to redirect all of my old domain request to my new domain using htaccess file. Below is what I am using but it does not work if the page is not on the new site. For e

相关标签:
5条回答
  • 2020-11-30 01:34

    This will direct everything from the old host to the root of the new host:

    RewriteEngine on
    RewriteCond %{http_host} ^www.old.com [NC,OR]
    RewriteCond %{http_host} ^old.com [NC]
    RewriteRule ^(.*)$ http://www.thenewdomain.org/ [R=301,NC,L]
    
    0 讨论(0)
  • 2020-11-30 01:36

    If your aim is to redirect all pages to a single maintenance page (as the title could suggest also this), then use:

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !/maintenance.php$ 
    RewriteCond %{REMOTE_HOST} !^000\.000\.000\.000
    RewriteRule $ /maintenance.php [R=302,L] 
    

    Where 000 000 000 000 should be replaced by your ip adress.

    Source:

    http://www.techiecorner.com/97/redirect-to-maintenance-page-during-upgrade-using-htaccess/

    0 讨论(0)
  • 2020-11-30 01:39
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
    RewriteRule ^(.*)$ "http://www.thenewdomain.com/" [R=301,L]
    
    0 讨论(0)
  • 2020-11-30 01:49

    Add this for pages not currently on your site...

    ErrorDocument 404 http://example.com/

    Along with your Redirect 301 / http://www.thenewdomain.com/ that should cover all the bases...

    Good luck!

    0 讨论(0)
  • 2020-11-30 01:53

    Are you trying to get visitors to old.com/about.htm to go to new.com/about.htm? If so, you can do this with a mod_rewrite rule in .htaccess:

    RewriteEngine on

    RewriteRule ^(.*)$ http://www.thenewdomain.com/$1 [R=permanent,L]

    0 讨论(0)
提交回复
热议问题