user1050185
user1050185

Reputation: 13

needed a suggestion in redirecting old URLs to a new URL

Earlier i have installed my code in the main domain itself. for instance,

www.abcd.com/xyz/page.html

there are about 300 pages indexed by google with the old URL.

Now i have removed that code from the main domain and installed the code in Sub-Domain. So it make all the URLs indexed by Google and all the backlinks are pointing to the old URL.

Now i need to point all the old invalid URL to new Valid URL when Users clicks on the old URL.

Please suggest how to handle this.

Thanks a lot...

Upvotes: 1

Views: 176

Answers (4)

zneak
zneak

Reputation: 138171

If you are using Apache, I suggest that you use mod_rewrite as it allows to send the HTTP status 301 Moved Permanently, informing search engines that the contents of your website has been moved to a new location (rather than just deleted).

In a .htaccess file:

RewriteEngine on
RewriteRule (.*) http://newdomain.mysite.com/$1 [R=301,L]

The first line enables URL "rewriting", the fancy term for redirections of all kind. The second line is decomposed like this:

  • RewriteRule is the directive to match URLs and change the place they point to;
  • (.*) is a regular expression matching any requested file path (without an initial slash)
  • http://newdomain.mysite.com/$1 is the place where you want to send your visitors, and $1 is expanded to the previously matched path
  • [R=301,L] tells Apache to send the 301 Moved Permanently HTTP status code, and that it's the last RewriteRule that can match this request (it's useful only when you have multiple RewriteRules but it doesn't hurt to have it anyways).

The next time crawlers visit your site, they will notice the HTTP status and update their links to your new address. You should have it set up as soon as possible before Google thinks your whole site went 404.

Upvotes: 4

Treffynnon
Treffynnon

Reputation: 21563

If you are using Apache as your web server you can use mod_rewrite or mod_alias command. This is more a server job and not a programming job.

You can put the following in a .htaccess file or in the vhost container.

mod_rewrite

RewriteEngine On
RewriteRule ^xyz/page.html$ new-page.php [L,NC,R=301]

See: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

mod_alias

Redirect permanent xyz/page.html http://domain.com/new-page.php

See: http://httpd.apache.org/docs/current/mod/mod_alias.html#redirect

PHP

You can use a Location header to perform a redirection:

header('Location: http://domain.com/new-page.php', true, 301);

Java

public void HttpServletResponse.setHeader(String name, String value)

See: http://docstore.mik.ua/orelly/java-ent/servlet/ch05_06.htm

Upvotes: 2

tastybytes
tastybytes

Reputation: 1308

This should be handled by the server, preferably using an htacces redirect

Upvotes: 0

Naftali
Naftali

Reputation: 146310

PHP:

header('Location: new.url.com');

Upvotes: -1

Related Questions