Forum Moderators: phranque

Message Too Old, No Replies

How do I redirect my page from .htm to .shtml?

         

That_Girl

2:27 pm on Aug 24, 2012 (gmt 0)

10+ Year Member



Ok, so I've recently changed my site and I'm using includes on it, this resulting with my pages being .shtml

How can I redirect all my pages from www.mysite.co.uk/page.html to www.mysite.co.uk/page.shtml via the htcaccess?

Also, my index is .htm and I want that to be redirected to the .shtml one.

Your help is loved! I've been searching around for hours and just cannot find anything.

g1smd

2:37 pm on Aug 24, 2012 (gmt 0)

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



I'm not sure where you're looking, because there's more than 20 000 threads with examples of redirects here.

The index page problem should be solved by
DirectoryIndex index.shtml
and you should redirect requests for all named index pages to root URL ending in a trailing slash. Never link to named index pages.

Use a
RewriteRule
with the
[R=301,L]
flags for each redirect. The pattern will be
^index.\html?$
for your root index page and
^(([^/]+/)*([^/.]+))\.html?$
or similar for the other pages.


SSI offers very limited functionality. I would have gone with PHP includes and moved the entire site to extensionless URLs at the same time.

[edited by: g1smd at 2:44 pm (utc) on Aug 24, 2012]

That_Girl

2:43 pm on Aug 24, 2012 (gmt 0)

10+ Year Member



g1smd: I'm sorry, I have absolutely no knowledge and understanding for redirects and I have no idea where to start. What code would I have to put in?

wilderness

3:02 pm on Aug 24, 2012 (gmt 0)

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



This forum was created in 2003 with intention (and charter restrictions) which made the theme of the forum "learning".

Copy and paste solutions were never an option and/or intended.

Please read the forum charter [webmasterworld.com], especially the portion on etiquette.

Please read the explanation g1smd offered and search the archives for those same references.

not2easy

3:02 pm on Aug 24, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



SSI offers very limited functionality. I would have gone with PHP includes and moved the entire site to extensionless URLs at the same time.

I agree completely with this suggestion. You could avoid these problems by going with includes. AFAIK most people stopped using .shtml several years ago.
As for the code to put in, you would do yourself a big favor to read through several other threads to get a good grasp of what you are trying to change and how to do that if you really want to take that path. The parts are here, but it is not a good practice to hand off lines of code for people to use. They never will learn more and it may not work for their particular server setup. Some information should be available from your host if you just want a quick fix.

incrediBILL

4:00 pm on Aug 24, 2012 (gmt 0)

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



I think you're getting URLs confused with file names because the two are not the same.

Why in the heck would you want to use .shtml? Just because you use includes doesn't mean you have to change the files to .shtml or include the .shtml in the URL itself, as I use SSI with .html files and no file names at all, completely extensionless.

FYI your index file should only redirect to "/", aka "example.com/" to avoid canonicalization issues in the SEs.

FWIW, for security reasons exposing any extension to the outside world is a bad idea because .shtml, .php, .asp, etc. just give hackers more clues how to start hacking at your server.

lucy24

4:54 pm on Aug 24, 2012 (gmt 0)

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



Just because you use includes doesn't mean you have to change the files to .shtml or include the .shtml in the URL itself, as I use SSI with .html files and no file names at all, completely extensionless.

Ditto. I even posted about my own venture into SSIs once. Not quite "If I can do it, anyone can" but pretty close.

The two options-- either one can go in .htaccess-- are

AddType text/html .html
AddOutputFilter INCLUDES .html


and

XBitHack on


The first version is for any directory where most html files will have includes. The second version lets you enable individual files (details depend on your setup) in cases where you don't want to slow down the server looking for Includes that generally don't exist.

The Apache docs include a tutorial on SSIs. By some weird oversight it is written in straightforward English that a normal human can understand.

If all you're including is literal text, there's no need for php. Especially useful if you're on shared hosting that charges for memory usage rather than disk space and/or bandwidth.

That_Girl

8:41 am on Aug 28, 2012 (gmt 0)

10+ Year Member



Sorry for my delayed reply.

I got told that .shtml was the way to go, so I changed every page to suit it.

Thanks all for your responses. What would be the best thing to do then? Use PHP includes, or use Lucy24's suggestion and the the 'AddOutputFilter INCLUDES .html' ?

incrediBILL

8:58 am on Aug 28, 2012 (gmt 0)

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



Lucy's method is what I do, works great.

That_Girl

9:10 am on Aug 28, 2012 (gmt 0)

10+ Year Member



I found that with the includes, they did slow my site down quite a bit.
I switched my nav from JavaScript to css which did help a bit, but are there any other tips on how to keep loading time down?

I'm not sure if there is anything, but I thought I'd ask anyway.

lucy24

4:56 pm on Aug 28, 2012 (gmt 0)

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



In the navigation case: are you sure it's load time rather than execution time? Javascript happens on the user's computer, which has practically got to be slower than the server. But if you can get rid of one auxiliary file entirely, that should help.

That_Girl

8:52 am on Aug 29, 2012 (gmt 0)

10+ Year Member



Lucy: Yes, pretty sure it's loading time. Our site that is currently up isn't using the includes and it loads quickly, also loading the whole page at once. Once the includes have been placed in, it shows only the header, then a few seconds later the nav comes, then the content and then the sidebar (the sidebar and nav being the includes).

That_Girl

2:24 pm on Aug 30, 2012 (gmt 0)

10+ Year Member



Turns out it was just the pages with the .shtml that were slow.
I put your suggestion to use, Lucy, and it works perfectly fine! Not slow one bit, so thank you very very much!

Includes are a new territory for me, so thanks for putting up with my dumbness.

Glad it's finally done, the site will be so much easier to edit now!