301 redirect

Hi E's, I want move a entire site do another server and another domain, and I have some doubts about the redirect.
I read in google sitemaps, that I have to inform in file .htaccess about that move, the problem is I don't understand that language.

In practice, I have 120 pages, and each page is in a different folder, like:

and in the new domain will appear in this way:
note: the files .htm will transform to .php files

What I have to do in .htaccess to made the correct 301 redirect?

The best regards, JC
Pedro ChagasWebmasterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you can write to .htaccess, include this

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

For more info, see http://www.webconfs.com/how-to-redirect-a-webpage.php
Pedro ChagasWebmasterAuthor Commented:
Hi, I'm confused!
I thing in your example I have to create a .htaccess file for all folder where is the file index.htm, correct?

Regards, JC
you should only have to create the .htaccess folder in the top level folder where you want it to work. it should automatically cascade down to all subfolders. Also, if you want to move an entire tree, you probably will want to put this into httpd.conf, if you have access to that.
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Ray PaseurCommented:
I think I might do it in PHP.  Presumably all of your scripts start with a common include() script - something that starts the session, connects the data base, etc.  In that script on the old server, you might take the value of $_SERVER["REQUEST_URI"], append it to the new domain and issue the header() statements.  You might also log the redirects to a data base if you wanted to see them occurring.  Just a thought, ~Ray
Pedro ChagasWebmasterAuthor Commented:
Hi @Ray Pauser, how I do that in php if all the files are .htm. I thing I cant write php in a .htm file, or don't?

Hi @mankowitz, can ypu give me a example for one file .htaccess and with 3 URL's?
This question is because I don't know how the system know the URL belongs.
???????RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]??????????????

Regards, JC
create a new file called .htaccess in the root directory of www.example.com, at the same level where the index.htm file is.

In that file, put the following text:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pedro ChagasWebmasterAuthor Commented:
The problem is the structure of the site. The main site stay in root and have a file index.htm too, the other index.htm stay all inside folders, folder1, folder2, etc.
You can see the structure here http://rdsrc.us/7L1N99
If you visit the link above you will see the main page. If you click in one of the links in the middle right or left, will open the other index.htm files, and that ones are in folders.

After you see my real problem what you suggest?

The best regards, JC
Ray PaseurCommented:
I think I cant write php in a .htm file, or don't?

You can parse .htm files through the PHP parser.  Use AddHandler to connect the file types and the parser.  But if the .htm files do not use PHP this might not be necessary.

You can put .htaccess files in the root directory and in the other directories, too.  
ok, one more time: you should only have to create the .htaccess folder in the top level folder where you want it to work. it should automatically cascade down to all subfolders.


suppose you have these directories


and you want to forward them all. If you put the .htaccess file in the "www/" directory it will work as though it was in all the other directories as well, because they are all children of that initial directory. Get it?
Pedro ChagasWebmasterAuthor Commented:
Hi, The html files not use PHP, when I create that project understanding Php was a dream. That project is pure html only.
But I'm curious about the Php Parser. I thing the best idea is create a header (with the 301 redirect) for each page, but my knolgment I thing I can't use Php in .html pages. Now you talking about the Php Parser, and sounds that is possible (use Php in html files).
Can you explain better the Php Parser? If was until for my case!
Or Should I open a new question?
Regards, JC
Pedro ChagasWebmasterAuthor Commented:
Hi @mankowitz, I get it!
By other words, and if I understand, that redirect you suggest working like a mirror?!
If I use that redirect, the same folders have to be create in the new server, correct?
Regards, JC
Pedro ChagasWebmasterAuthor Commented:
Hi E's, I'm note close this question yet, because I'm waiting a answer from my hosting support.
Soon I be back to assign the points and close the question.

The best regards, JC
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.