Forum Moderators: phranque

Message Too Old, No Replies

Adding a .shtml extension without problems?

         

HaloPlayer

9:03 am on Aug 17, 2015 (gmt 0)

10+ Year Member



Is it possible to do a rewrite for a dynamic URL to add a .shtml extension? Or would there be a adverse side effect?
http://www.example.com/book.php?name=farawaytree
to become:
http://www.example.com/book/name/farawaytree.shtml

Thanks!

lucy24

8:16 pm on Aug 17, 2015 (gmt 0)

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



Do you mean, so you can use SSIs without changing the URLs? Sure, you could do that, just like you could rewrite URLs in .html to serve up .php pages. But, unlike the php analogy (which I thought of because I actually do it here and there), there are alternatives. The simplest is just to say
AddOutputFilter INCLUDES .html .php
Or, if only a few specific pages are involved, there's the X-Bit Hack, which is less scary than it sounds.

But wait. Will your pages no longer be using php content? Otherwise you'd need to throw in a different AddOutputFilter line to parse all your shtml pages for php, and then what was the point of changing? If you're already in php, why not just use php includes for everything?

You said "rewrite" but I can't help noticing that the second URL is "prettier" than the first one. Did you really mean an external redirect as part of changing your whole URL structure? At this point, some people would be encouraging you to think about going extensionless. My personal reaction to an extensionless URL is "Go back in the server and put some clothes on!" but this is, I think, a minority opinion.

robzilla

10:03 pm on Aug 17, 2015 (gmt 0)

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



Why .shtml instead of .html or, indeed, no extension at all? For webpages, extensions are a waste of bytes.

Also, I don't know whether these examples resemble your actual URL structure, but I would probably rewrite /book.php?name=farawaytree to /book/faraway-tree whenever possible, and preferably also include an ID, e.g. /book/faraway-tree-7392, to avoid problems with duplicate or changing book titles. Then you could pass the numerical ID to your PHP script, e.g. /book.php?id=7392.

HaloPlayer

10:48 am on Aug 18, 2015 (gmt 0)

10+ Year Member



Thank you for the replies!
The site in question has always run .shtml (yes its dated lol) now we think it's time to move over to php to run things, so all the content will be handled by php (just simple includes etc.) so rather than change links and lose Google SEO etc. I thought that just doing a rewrite would be the logical answer, that way everything stays the same regarding links and such.
The other option is of course do a permanent redirect and just do a rewrite to extensionless URL's., but I must admit I fancy the idea of rewriting to .shtml.

robzilla thanks for the suggestion and I understand what you are saying, the content is always entered and handled manually so the chances of duplicate content and slim to none.

lucy24

6:02 pm on Aug 18, 2015 (gmt 0)

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



has always run .shtml ... now we think it's time to move over to php to run things

Oh. So when you said "from A to B" you really meant "from B to A" ;) Sure, you can rewrite from any extension to any other extension-- or, of course, from no extension to the extension of your choice. The server doesn't care.

If you rewrite from a visible (s)html to a hidden php it makes it look as if your site is still old-fashioned hand-rolled html. Nobody-- not even the googlebot-- will know what's really going on.

Edit: For safety's sake you should also make a rule going in the other direction, so that requests for .php by name (RewriteCond looking at %{THE_REQUEST}) are either redirected or blocked (your choice).

HaloPlayer

11:11 am on Aug 19, 2015 (gmt 0)

10+ Year Member



Thanks lucy24!
I'll formulate a rewrite and post it to see what you think.
Thanks again! :-)

HaloPlayer

1:25 pm on Aug 21, 2015 (gmt 0)

10+ Year Member



I think this is sufficient in terms of the rewrite:

RewriteEngine On
RewriteRule ^book/name/([-a-z0-9_]+)\.shtml$ /book.php?name=$1 [L]


Thoughts?

lucy24

6:08 pm on Aug 21, 2015 (gmt 0)

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



If all your URLs fit into that pattern, then yup, that should do it.

Take an occasional look at your logs and make sure nobody (other than yourself) is requesting /book.php by name.