Forum Moderators: phranque

Message Too Old, No Replies

Htaccess from HTM to PHP

Htaccess from HTM to PHP

         

alfatec

5:56 pm on Jul 14, 2009 (gmt 0)

10+ Year Member



Hi, I work in a school and have just implemented a new school website. Now the old website was a standard htm site hosted on a Windows web server based in the local authority and the URL was www.example.place.sch.uk.

Now the new site is a PHP site and hosted on our Apache web server and the site is called www.example.co.uk.

The DNS was changed to route all traffic from the old one to the new site so if I put the old site into google it takes me to the new one. What I would like to do is redirect from the old URL to the new URL. I have tried to put a htaccess file on the Apache server but as soon as I do the redirect I cannot access the new website.

I can no longer access the old windows web server as the DNS is pointing all traffic to the new web site. When I search Google for Sale Grammar School it still brings up the old site. Any help would be appreciated.

[edited by: jdMorgan at 6:14 pm (utc) on July 14, 2009]
[edit reason] examplified [/edit]

jdMorgan

6:15 pm on Jul 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If both the old domain and the new domain now point to the new domain on the new server, you should be able to use mod_rewrite to do these redirects. I suggest mod_rewrite because it has the capability to be 'aware' of the requested domain, and so provide for a complete solution to the various incorrect URLs that might be requested (e.g. errors in the domain, errors in the URLs, or both).

If the old domain is not pointed to the new server, then getting that done is your first step.

If there is a fixed and predictable relationship between the old and new URLs, such as
oldomain.sch.uk/page-name.html -> newdomain.sch.uk/same-page-name.php
then you can redirect all page URLs with a single RewriteRule. If not, then I'm afraid that you'll have to write many rules, each of them a one-off for each old URL (Consider redirecting only the most important ones if you have more than a few hundred).

If you added code and it made your site inaccessible, then obviously there's something amiss with the code. But we can't comment further without seeing the code (or a representative sample of it).

Jim

alfatec

7:53 pm on Jul 14, 2009 (gmt 0)

10+ Year Member



I have had a quick go at the redirect and managed to redirect the olddomain.sch.uk/index.htm to newdomain.co.uk/index.php but when I try and put a whole site redirect from .*htm to newdomain.co.uk without a index.php then the site does not work. I will post the code I am trying.

g1smd

8:11 pm on Jul 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You should refer to index pages in URLs without mentioning the name of the index file itself. End the URL with a trailing slash after the domain name and folder name.

If new filenames differ from old filenames only by their extension then there is no need to change the URL by which they are referred to 'out on the web'. Google has no need to know that your pages are now generated by PHP when they used to be generated by static HTML files. No need to know at all.

alfatec

10:42 am on Jul 15, 2009 (gmt 0)

10+ Year Member



Hi, I have been trying the following code:
RewriteEngine on
RewriteRule (.*) http://www.example.co.uk/$1 [R=301,L]

but it just seems to send the site into a loop, any ideas?

[edited by: jdMorgan at 6:44 pm (utc) on July 15, 2009]
[edit reason] example.com [/edit]

jdMorgan

2:56 pm on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're redirecting unconditionally, so you'll always redirect the client. And that's a loop.

So don't redirect unless the requested domain is "old" or "wrong":


RewriteEngine on
#
RewriteCond %{HTTP_HOST} !^www\.example\.co\.uk$
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L]

(On the RewriteCond pattern, "!" means "NOT")

Jim

[edited by: jdMorgan at 6:52 pm (utc) on July 15, 2009]

alfatec

5:50 pm on Jul 15, 2009 (gmt 0)

10+ Year Member



Hi jd, many thanks for that, it is now working a treat.
Many thanks for your kind help and experience in assisting me in resolving this matter. If we were in the same town, I would buy you a very large beer.

Best regards

jdMorgan

6:56 pm on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you're welcome -- and welcome to Dallas, TX any time. ;)

To continue with what g1smd was telling you above, you should link to www.example.co.uk/ rather than to www.example.co.uk/index.php on all of your pages, and then if a client requests index.php, index.html or index.htm directly, you should redirect that request to "/".

This rule, inserted *before* the one above, would do that for index files in any directory:


RewriteCond %{THE_REQEUST} ^[A-Z]+\ /([^/]+/)*index\.(php¦html?)([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(php¦html?)$ http://www.example.co.uk/$1 [R=301,L]

Replace the broken pipe "¦" characters with solid pipes before use; Posting on this forum modifies the pipe characters.

Jim