Reputation: 301
I wanted to ask you a question about 301 URL redirection. So, I have a website and it's former URL used to be:
http://www.sample.com/tutorials.php?name=sample
But, now it's:
http://www.sample.com/tutorials/programming/sample.php
So, you can conclude that the syntax of the new URL is this:
http://www.sample.com/tutorials/(name of the category)/(value of the variable).php
I've been toying around with 301 redirect, but I got 500 Internal server error when I used this code:
RewriteEngine On
RewriteCond %{COND ^tutorials.php?name=sample$ HTTP/1.1} ^[A-Z]{3,9}\ /tutorials\.php\?name=([^&\ ]+)
RewriteRule ^ /tutorials/programming/%1.php [L,R=301]
I have also tried to create my own 301 redirect code, which gives me no 500 Internal server error, but I don't know will it work (I can't test it on localhost, because search engines don't index localhost). Here it is :
RewriteEngine On
Redirect 301 /tutorials.php?name=$1 http://www.sample.com/tutorials/programming/(.+)\.php
So, if my code above is good than great, but if it's not, can someone please explain (as slowly and as detailed as possible, please) how to 301 redirect my old site to my new one. As I mentioned, I use dynamic web-sites and I am rewritting using .htaccess file (mod_rewrite).
I have tried to be as detailed as possible. If you need additional details, feel free to ask.
Upvotes: 0
Views: 1152
Reputation: 2703
You have to redirect the old links to your new domain. This is how you can do it.
Using htaccess:
Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain. The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
In addition to the redirect I would suggest that you contact every backlinking site to modify their backlink to point to your new website.
Note: This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.
Refer this for more methods
EDIT:
Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Upvotes: 1