的.htaccess 301旧域名重定向到新的领域,而页面和URL结构是相同的到新、重定向、领域、结构

2023-09-02 00:33:59 作者:埃菲尔铁塔的微笑、

我要重定向 http://olddomain.com 以 HTTP:/ /newdomain.com 为我所有的urls..keeping页面上相同的新领域。 我的意思是说的网址,如以下

I want to redirect http://olddomain.com to http://newdomain.com for my all urls..keeping the page on new domain same. What i mean to say is URLs such as below

http://olddomain.com/home/category/page.html
http://olddomain.com/home/mybook/page2.html
http://olddomain.com/login

should be 301 redirect to the new newdomain but same pages, like below

http://newdomain.com/home/category/page.html
http://newdomain.com/home/mybook/page2.html
http://newdomain.com/login

这是我在我的.htaccess目前

this is what i have in my .htaccess currently

RewriteEngine on
RewriteCond $1 !^(index.php|img|public|robots.txt) [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]

请帮我做这件事干净,exlpain事情的细节,因为我是新本。

Please help me to do this cleanly and exlpain things in details since i am new in this.

也没有人知道多少时间,搜索引擎可能需要从我olddomain重定向的引用搬走?我的意思是在搜索查询中的老域名的URL应该用新域的网址被替换,...​​,N旧域应该从搜索引擎消失。

also does someone know how much time search engines might take to move away from the references of my olddomain? i mean the old-domain urls in search queries should be replaced by new-domain urls... n old domain should go away from search engines.

推荐答案

添加以下code处的.htaccess的开始 -

Add following code at the beginning of .htaccess -

    RewriteEngine On

    # Redirect Entire Site to New Domain
    RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^another.olddomain.com$ [NC]
    RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]