Forum Moderators: coopster

Message Too Old, No Replies

php to html urls

What’s the best way to server php to old html urls?

         

ie111

9:46 am on Mar 16, 2010 (gmt 0)

10+ Year Member



Hi everyone,

I hope someone can help please, I am doing work on my site for the first time been learn here and there but not a web designer.

My site was built in html and in tables about 10 deep and was very messy, I had the mark up for the site rebuilt about a year ago and it was built in php a htaccess file was added with the below code to sever the php to the old html urls as i did not want to change the page names for the site.

[size=2]Options +FollowSymLinks
RewriteEngine On

# rewrite php extensions to html

RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^([^/]*).html$ $1.php[/size]


The problem is you can now see both the php pages and the html pages for the site, its a static brochure site running on a apache server please see the http header response for the site below (not sure this will help you guys).

[size=2]HTTP/1.1·200·OK(CR)(LF)
Date:·Tue,·16·Mar·2010·09:33:59·GMT(CR)(LF)
Server:·Apache/2.0.63·(Unix)·mod_ssl/2.0.63·OpenSSL/0.9.7a·mod_auth_passthrough/2.1·mod_bwlimited/1.4·FrontPage/5.0.2.2635(CR)(LF)
X-Powered-By:·PHP/4.4.7(CR)(LF)
Connection:·close(CR)(LF)
Transfer-Encoding:·chunked(CR)(LF)
Content-Type:·text/html(CR)(LF)
(CR)(LF)[/size]


I want to show only the html pages for the site when searching for it, not two so need to stop being able to see the page ending in php.

What is the correct way to have this please?

Many thanks for any help received here..

jatar_k

2:02 pm on Mar 16, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can actually leave the old html pagenames if you can have the html extension parsed for php. You would probably have to ask your host if that's possible.

a nice old thread on the topic
[webmasterworld.com...]

ie111

3:50 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



Hi Jatar,

I am very grateful for your reply...

So the way its set up at the min is wrong I take it?

So if the below code was added to the .htaccess file this might show the pages built in .php as the old page names which are in html? and not show when search for the .php pages.

At the minute your can find for example

www.mysite.com/contact-us.php

and

www.mysite.com/contact-us.html

for all of the pages on the site I only want to show the .html page.

Would the code above in my first post already in the htaccess file have to be removed from the htaccess file?

Below taken for the thread you showed me,

AddHandler application/x-httpd-php .html .php


Many thanks,

jatar_k

4:04 pm on Mar 16, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> So the way its set up at the min is wrong I take it?
it wouldn't be my first choice but you never know why things end up the way they do

the dupes are definitely an issue, as I said, check with the host first to see if it is ok to setup parsing for php in the html extension.

if so I would have them make the change to apache and then I would remove the rewrite rule

I would then test numerous requests and a php file switched to html to be sure it is working before making any more changes

after that would be to remove html files and rename all the php files to html and test some more along the way

depending on what is ranking or visible in search engines none of these changes might be advisable, maybe the best thing would be to nuke all the html files and leave the php

you might need to add some 301s for the files that are taken away as you may be losing valuable traffic

there are a lot of variables in play here. Why does it need to be html?

ie111

4:30 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



Hi Jatar,

Many thanks for the reply,

What happened is I got a company to rebuilt the code of the site.

I asked for the site to be built in xhtml and they built it in php and then used the .htaccess file to show the pages as www.mysite.com/contact-us.html

I do not wont to have any pages showing

www.mysite.com/contact-us.php

and now you can find both and i only wanted the

www.mysite.com/contact-us.html

I have only just seen for myself what’s been done when I recently downloaded a copy of my site.

I have only just started to learn things you see.

So I am not sure what to do have the code changed to be xhtml and not php or do what we have talked about?

Many thanks once again.

jatar_k

4:34 pm on Mar 16, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, your best bet may be to follow the steps I laid out above then

check with the host first to see if it is ok to setup parsing for php in the html extension.

if so I would have them make the change to apache and then I would remove the rewrite rule

I would then test numerous requests and a php file switched to html to be sure it is working before making any more changes

after that would be to remove html files and rename all the php files to html and test some more along the way

TheMadScientist

5:33 pm on Mar 16, 2010 (gmt 0)

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



Options +FollowSymLinks
RewriteEngine On

# redirect original requests for php extensions to html
# but do not redirect the internal requests (rewrites)

RewriteCond %(THE_REQUEST} \.php
RewriteRule ^([^.]+)\.php$ http://www.example.com/$1.html [R=301,L]

# rewrite php extensions to html

RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^([^.]+)\.html$ $1.php [L]

# I edited your regular expression a bit to 'anything not a dot' rather than
# 'anything not a /' and escaped the dot (\.) for a literal dot match rather than
# a match of 'anything except the end of a line.' I also switched from * (0 or
# more times) to + (1 or more times) because you should have at least 1 character
# after the / (not present in the .htaccess file for matching, except in certain
# predefined server variables) to have a valid location. Finally I added the [L]
# Last Flag which you should always use, unless you know you don't need to use it
# and why.

ie111

6:24 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



Many many thanks for your time and your reply, I just added the below code to the .htaccess file and deleted the other code in there the site still works but the php pages can still be reached.

For example I can still go to the below page, and I dont want to server a copy of these php pages only the pages ending in .html so only one copy for each page.

www.mysite.com/contact-us.php

[size=2]Options +FollowSymLinks
RewriteEngine On

# redirect original requests for php extensions to html
# but do not redirect the internal requests (rewrites)

RewriteCond %(THE_REQUEST} \.php
RewriteRule ^([^.]+)\.php$ http://www.example.com/$1.html [R=301,L]

# rewrite php extensions to html

RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^([^.]+)\.html$ $1.php [L][/size]

TheMadScientist

7:11 pm on Mar 16, 2010 (gmt 0)

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



Empty your browser cache and try again...
The code should work as posted.

If not let me know, there might be some goofy anomaly with your server, but otherwise I don't see any errors keeping the code I posted from doing what you would like.

THE_REQUEST contains the original request string, so the check is to see if the original request sent to the server contained .php and if so it should be redirected to .html. Then the other code kicks in.

ie111

8:18 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



Hi again,

I am very grateful for your help here thank you...

I just created a new .htaccess file with the below code and uploaded it (changing http://www.example.com to my website name of course) I just cut and pasted the below code from the .htaccess file.

I refreshed the browser and I could still see the unwanted .php page extensions pages.

It is working but still show these unwanted pages.

Very sorry for being a pain here :-)

I dont understand this very sorry how would I check this?

Would the http header response for the site in the first post answer this guessing here sorry.

THE_REQUEST contains the original request string, so the check is to see if the original request sent to the server contained .php and if so it should be redirected to .html.





[size=2]
Options +FollowSymLinks
RewriteEngine On

# redirect original requests for php extensions to html
# but do not redirect the internal requests (rewrites)

RewriteCond %(THE_REQUEST} \.php
RewriteRule ^([^.]+)\.php$ http://www.example.com/$1.html [R=301,L]

# rewrite php extensions to html

RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^([^.]+)\.html$ $1.php [L][/size]

TheMadScientist

8:22 pm on Mar 16, 2010 (gmt 0)

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



I refreshed the browser and I could still see the unwanted .php page extensions pages.

Did you refresh or did you go into your browser settings and empty your browser cache? If you have the page cached, especially in IE, you will not be redirected because your browser still has the page you requested in the cache and does not request the page from the server. Refreshing the page will not do the trick. You need to make sure you actually empty the browser cache so the location is requested from the server again... As a rule, when ever you make a change to your .htaccess file, you should always manually empty your browser cache to check the results of the change rather than only refreshing the page.

Another thing you can do is go to your control panel here and look for the server header check and then put the URL with the .php extension in and see if it returns a 301 redirect to the .html version of the page. This will tell you if other people are being redirected and it's your browser or not.

ie111

8:48 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



Hi i went on to another pc cleared all the history and checked also checked the http header responce.

Please see below not getting a 301 but a 200 responce, many thanks, and thanks for bearing with me here...

HTTP/1.1·200·OK(CR)(LF)
Date:·Tue,·16·Mar·2010·20:42:08·GMT(CR)(LF)
Server:·Apache/2.0.63·(Unix)·mod_ssl/2.0.63·OpenSSL/0.9.7a·mod_auth_passthrough/2.1·mod_bwlimited/1.4·FrontPage/5.0.2.2635(CR)(LF)
X-Powered-By:·PHP/4.4.7(CR)(LF)
Connection:·close(CR)(LF)
Transfer-Encoding:·chunked(CR)(LF)
Content-Type:·text/html(CR)(LF)
(CR)(LF)

TheMadScientist

8:58 pm on Mar 16, 2010 (gmt 0)

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



Hmmmmm...

Not sure what to tell you except to make the rule very broad and use the match from the condition for the redirect.

It should work as far as I can tell.
(I use a similar rule set in more than one .htaccess file.)

Options +FollowSymLinks
RewriteEngine On

# redirect original requests for php extensions to html
# but do not redirect the internal requests (rewrites)

RewriteCond %(THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.php
RewriteRule .? http://www.example.com/%1.html [R=301,L]

# rewrite php extensions to html

RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^([^.]+)\.html$ $1.php [L]

ie111

9:30 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



Thank you again...

Just tryed both sets of code again and and got the google bot to fetch the pages on both still a 200 responce...

I am very very greatful for all your help today you a gent, thank you.

ie111

8:47 am on Mar 17, 2010 (gmt 0)

10+ Year Member



I just got on to the company who built the site to see what could be done.

You see I asked for the site to be built in xhtml/css as i was starting to learn xhtml/css but my skills are basic but I can do bits and bobs, but i cant work in php at all.

But the site was built in php and then rendered as xhtml I told the company even its rendered as xhtml its still built in php which I can’t work in.

And also there is the problem now with all the un wanted php pages showing up as well, and if it was built as I asked and as we agreed there would be none of these duplicated pages.

I think I need to get the site put in xhtml this would make the site easy for me to work on and remove the unwanted .php pages.

It’s a 15 page static brochure website I think it would work just as well in xhtml?

If you guys were asked to built a site in xhtml/css would you then go and built it in php and render it as xhtml to make updates easier?

Any thoughts would be really appreciated here.

ie111

10:25 am on Mar 18, 2010 (gmt 0)

10+ Year Member



Hi,

An update the company said the best idea is to the change the site to html5.

Is this a good idea?

I know some of the usual code is not used in html5 but will this cause any problems?

And will html5 be simualar to using xhtml what I am used to?

Many thanks for any thought recivied.

rocknbil

5:18 pm on Mar 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, we're veering off topic, but let's bring a little sensibility to the table.

You say,

It’s a 15 page static brochure website I think it would work just as well in xhtml?


So there are no dynamic features at all, no CMS, the content itself does not come from a database? "Yes" on the surface, but "xhtml" has bearing on your next question,

An update the company said the best idea is to the change the site to html5.
Is this a good idea?


Short answer, most likely, yes, an html 5 doctype should be fine. But you need to understand why. Don't let them tack on an html 5 "surcharge."

I say that (tongue in cheek) because they may very well see you don't understand these terms or what their affect is.

The first question is, do you know why you are using XHTML? The "root" directive of XHTML is to extend the standard HTML set, that is, you can create your own custom DTD and create your own tags to give words context. Example, you can distinguish Titanic the movie from Titanic the ship, and these extensions are intended to be used by machines (search engines) to better understand the document. Unfortunately, this never took off, and 99% of the sites out there are "vanilla html" which are better described by an HTML doctype. But for some reason, the idea "stuck" that "XHTML is the latest and greatest." Everyone seems to have forgotten what it was the greatest for. :-)

HTML 5 is the next generation of HTML, with added features ,etc., and is likely to be the replacement for both (although there is an XHTML revision in the works . . . )

I've probably buried you in techno babble, but the bottom line is that if your pages are vanilla HTML without extension, yes, an HTML 5 doctype should be fine. But creating and validating an HTML 5 doctype is no more difficult than HTML or XHTML, so don't let them tell you this is more difficult or will be more costly.

Know what they are saying so you can make an educated decision - although these excellent threads don't cover HTML 5, they will give you an understanding of the ramifications of doctypes:

Choosing the best doctype for your site [webmasterworld.com]
Why most of us should not use XHTML [webmasterworld.com]

My personal opinion in scanning over this thread, there has to have been some miscommunication between you and the provider. You start off wanting to do a mod_rewrite to get html extensions from php files, and now it's sounding like you want to manually edit the files. As a provider I can tell you it would be insane (or stupid, on my part) to create a dynamically generated site when a client requests static files, UNLESS the word "CMS" was thrown in there somewhere.

If they added a CMS for you, you are missing out on the best part of a CMS by going to manual editing. Learn how to use it, sort out the rewrite issues, you'd be better off.

ie111

8:42 pm on Mar 18, 2010 (gmt 0)

10+ Year Member



Wow,

What a great reply thank you for your time and your wisdom.

I have zero no how on code (i am ok at seo) and this is of help. Sorry for going of topic here I didn’t want to go around starting new threads.

Many thanks once again, I want to learn code and that what I’m going to do, I have asked them to put the files as html files and I don’t want the site to be in html5 after reading all day today on the net as I would not be able to code it myself in html5 and get the site to work in ie6.

So the site is going to lose the php and leave the doc type as xhtml and I can do most of the basic code in xhtml without get into problems with browsers.

HTML5 is too advanced for me, to you guys it’s no problem but me no being a web designer it is.

Readie

8:53 pm on Mar 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



and get the site to work in ie6.

I'm under the impression we're all supposed to be dropping support for IE6 to try and force it out of use.

That is: make the site useable, but don't worry too much about imperfections when viewed in IE6.

ie111

10:03 pm on Mar 18, 2010 (gmt 0)

10+ Year Member



Hi Readie,

About 30 per cent of the people who visit my site view it in ie6, when I had the sites mark up rebuilt a year ago (the old site did not look right in ie6 but after the rebuilt it did) the bounce rate for the home page dropped on average from 37% to 18%.

Readie

10:33 pm on Mar 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Widespread calls for the dropping of IE6 only started a few months ago - so I suggest re-collecting your data.

If it's still a high percentage, then by all means make the site with IE6 in mind - but be aware that many large sites are dropping support for IE6 and pushing for it to be deprecated entirely, so the cost => return of building your sites for IE6 is decreasing by the day.

ie111

12:06 am on Mar 19, 2010 (gmt 0)

10+ Year Member



I still get over 30% of my custom from people using ie6, people in offices and at work, there companys still use ie6.