简体   繁体   English

301将旧网址重定向到新网址-Codeigniter

[英]301 redirect for old urls to new urls - codeigniter

I hope to get some help here. 我希望在这里得到一些帮助。 We had a static php website for a few years and recently we redesigned the site in codeigniter. 我们有一个静态的php网站已有几年了,最近我们在codeigniter中重新设计了该网站。 Now after redesign many of our urls have changed, eg 现在,在重新设计之后,我们的许多网址已更改,例如

example.com/about_us became example.com/about example.com/about_us成为example.com/about
example.com/programs-list became example.com/programs example.com/programs-list变为example.com/programs
and so on. 等等。

Our old urls were throwing up a 404 error. 我们的旧网址抛出404错误。 We asked the developer to add a 301 redirect for the old urls so that our SEO juice is fully passed on by google to the new urls. 我们要求开发人员为旧的网址添加301重定向,以便我们的SEO程序完全由Google传递给新的网址。 The developer says he has given a redirect using the routes.php file (and it is working) but I am not sure if it is really a 301 redirect. 开发人员说他已经使用routes.php文件进行了重定向(并且正在工作),但是我不确定这是否真的是301重定向。 In most cases I have seen, a 301 redirect is added using the htaccess file. 在大多数情况下,我使用htaccess文件添加了301重定向。 What is happening is that now when we go to the link example.com/about_us (which was the old url) it does display the contents of the new page (example.com/about) but the url in the address bar still stays example.com/about_us. 发生的事情是,现在当我们转到链接example.com/about_us(这是旧的URL)时,它确实显示了新页面的内容(example.com/about),但地址栏中的URL仍然是示例.com / about_us。 My understanding is that if we add a 301 redirect it should simply redirect the link from example.com/about_us to example.com/about in the address bar. 我的理解是,如果我们添加301重定向,则只需将地址栏中的链接从example.com/about_us重定向到example.com/about。 At the moment both of pages example.com/about and example.com/about_us are loading. 目前,example.com / about和example.com/about_us两个页面均已加载。 Is this the correct way or are we missing something. 这是正确的方法还是我们遗漏了一些东西。

Appreciate your guidance. 感谢您的指导。

Thank you 谢谢

Here is my htaccess: 这是我的htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
#  slashes.
# If your page resides at
#  http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
RewriteRule ^(about_us)\.php$ /about/$1 [R=301,NC,L,QSA]
</IfModule>

.htaccess redirect .htaccess重定向

for same url use following code 对于相同的URL使用以下代码

      Redirect 301 /oldfile.htm /newfile.htm

Add this code or create new .htaccess file in the old-page.html directory. 添加此代码或在old-page.html目录中创建新的.htaccess文件。 Single URL redirect Permanent redirect from old-page.html to new-page.html. 单个URL重定向从old-page.html永久重定向到new-page.html。 .htaccess: .htaccess:

       Redirect 301 /old-page.html http://www.example.com/new-page.html

Entire domain redirect 整个域重定向

Permanent redirect from all domain pages to newdomain.com. 从所有域页面永久重定向到newdomain.com。 .htaccess file should be at the old website's root directory. .htaccess文件应位于旧网站的根目录中。 .htaccess: .htaccess:

             Redirect 301 / http://www.newexample.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM