Discussion:
Content Negotiation via .htaccess
(too old to reply)
Ronnie MacGregor
2008-10-30 17:02:48 UTC
Permalink
Anyone any experience with this ?

In my test on a production server where I have no access to the Apache config
file, the use of Options +MultiViews in the root .htaccess simply changes the
result from :

404 Not Found to 403 Forbidden

when the requested .htm page does not exist, but the same name .php does.


Primary aim ... serve .php on request of same name .htm

.... but also to eliminate the need for file types in the URI
--
Ronnie MacGregor
Scotland

Ronnie at
dBASEdeveloper
dot co dot uk

www.dBASEdeveloper.co.uk
David Ball
2008-11-01 18:19:57 UTC
Permalink
Hi Ronnie

Are you converting a site from html to php?
... and all the existing links and everything refer to html
pages?

If so, that's the problem I had. I won't waste your time
with the low-tech solution I use, unless that's where you
are now. (You've probably already thought of it yourself
anyway.)

Thanks
David Ball
www.ChelseaData.ca
Post by Ronnie MacGregor
Anyone any experience with this ?
In my test on a production server where I have no access
to the Apache config
file, the use of Options +MultiViews in the root .htaccess
simply changes the
404 Not Found to 403 Forbidden
when the requested .htm page does not exist, but the same
name .php does.
Primary aim ... serve .php on request of same name .htm
.... but also to eliminate the need for file types in the
URI
--
Ronnie MacGregor
Scotland
Ronnie at
dBASEdeveloper
dot co dot uk
www.dBASEdeveloper.co.uk
Ronnie MacGregor
2008-11-02 09:37:11 UTC
Permalink
On Sat, 1 Nov 2008 14:19:57 -0400
Post by David Ball
Are you converting a site from html to php?
... and all the existing links and everything refer to html
pages?
Yes ... well guessed. <g>

This is a site where we are getting an increasing number of direct visitors who
have bookmarked or who have been emailed a link. We want to ensure that these
visitors land on the same name .php page.

There's more to it than that though, with content negotiation the need for file
type declaration in the URI is gone, and Apache should find the "best match"
resource. This opens up a whole range of possibilities .... I just need to get
it to work !!! The documentation is pretty much devoid of example.
Post by David Ball
If so, that's the problem I had. I won't waste your time
with the low-tech solution I use, unless that's where you
are now. (You've probably already thought of it yourself
anyway.)
I'm quite happy to compare low-tech solutions .....

You get yours out first !! <g>
--
Ronnie MacGregor
Scotland

Ronnie at
dBASEdeveloper
dot co dot uk

www.dBASEdeveloper.co.uk
David Ball
2008-11-02 14:15:41 UTC
Permalink
I love documentation - it's so ... optimistic.<g>

I've tried a bunch of things with Apache but with only
limited success. If you have lots of spare time, mod_rewrite
is good for weeks of entertainment. I usually give up
eventually, unless it's something really important. As
you've said, examples can make all the difference. A good
thick O'Rielly manual would probably clear things up too.

This "solution" came up while making the transition to php,
and the existing html files were still around. I just
replaced the html with some code that points to the php
file. For example, this would be index.html:

<html>
<script type="text/javascript">
<!--
window.location = "index.php"
//-->
</script>
</html>

Sometimes, ya gotta do what ya gotta do.
Post by Ronnie MacGregor
On Sat, 1 Nov 2008 14:19:57 -0400
Post by David Ball
Are you converting a site from html to php?
... and all the existing links and everything refer to
html
pages?
Yes ... well guessed. <g>
This is a site where we are getting an increasing number
of direct visitors who
have bookmarked or who have been emailed a link. We want
to ensure that these
visitors land on the same name .php page.
There's more to it than that though, with content
negotiation the need for file
type declaration in the URI is gone, and Apache should
find the "best match"
resource. This opens up a whole range of possibilities
.... I just need to get
it to work !!! The documentation is pretty much devoid of
example.
Post by David Ball
If so, that's the problem I had. I won't waste your time
with the low-tech solution I use, unless that's where you
are now. (You've probably already thought of it yourself
anyway.)
I'm quite happy to compare low-tech solutions .....
You get yours out first !! <g>
--
Ronnie MacGregor
Scotland
Ronnie at
dBASEdeveloper
dot co dot uk
www.dBASEdeveloper.co.uk
David Ball
2008-11-02 18:14:36 UTC
Permalink
Hmmmm ...... you did say "low-tech" !! <bg>
You are relying on client side javascript being switched
on for it to work,
.... around 10% of users have it switched off.
Bots don't get educated as to the new file name with a
301.
If someone has JavaScript turned off, this will be just one
more thing requiring manual intervention. I'm one of the 10%
(Firefox NoScript, etc.), so I know all about stuff not
working.
"Bot education" is not really up there on my list of
priorities. I consider it a luxury to not have to worry
about these scavengers, and I realize that others are under
pressure to sell more crap<g>. As for me, I've moved into a
post-nirvana state. I am now trying to achieve total
maintenance-freedom. (For anyone challenged by this, it
means "I'm getting old and lazy. I'm not going to fix
this.")
######################################
#
# Rewrite *.htm or *.html requests
# to *.php when same name *.php exists
# and flag as permanent move
#
# Ronnie MacGregor
# www.dBASEdeveloper.co.uk
#
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.htm$ $1 [NC,C,E=OldType:htm]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [S=1,R=301,L]
RewriteCond %{ENV:OldType} ^htm$
RewriteRule ^(.*)$ $1.htm [L]
RewriteRule ^(.*)\.html$ $1 [NC,C,E=OldType:html]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [S=1,R=301,L]
RewriteCond %{ENV:OldType} ^html$
RewriteRule ^(.*)$ $1.html [L]
#
######################################
Might be a slightly cluncky approach, but it seems to be
working fine so far.
Can you decode it ? <g>
Thanks for that - you've undone years of therapy. The
repressed memories emerge ... the horror ... the horror ...
gaaahhhhhhhhhhhhhhhhhhhhh! <rolling into a fetal position>.
No, I'm not even going to try to decode it. <g>

David Ball
Geoff Wass [dBVIPS]
2008-11-03 05:40:17 UTC
Permalink
Post by David Ball
Thanks for that - you've undone years of therapy. The
repressed memories emerge ... the horror ... the horror ...
gaaahhhhhhhhhhhhhhhhhhhhh! <rolling into a fetal position>.
No, I'm not even going to try to decode it. <g>
David Ball
David,

Are you sure that's not caffeine withdrawal?
--
Geoff Wass [dBVIPS]
Montréal, Québec, Canada

.|.|.| dBASE info at http://geocities.com/geoff_wass |.|.|.
.|.|.| ---------------------------------------------------------- |.|.|.
.|.|.| IT Consultant http://Geoff_Wass.com |.|.|.
David Ball
2008-11-04 00:18:19 UTC
Permalink
Hmmm.... it was only 1:14pm. Even with the time change, I
think I was still basking in the sweet warm glow of
well-caffeinated Sunday morning coffee. I may have sadly
bade farewell to my second cup by that time, but the
gloriouos oh-what-a-feeling was still coursing through my
veins. I mean, can't you tell by the inspirational uplifting
tone in my writing?<g>



"Geoff Wass [dBVIPS]" <***@attglobal.net> wrote
in message
Post by Geoff Wass [dBVIPS]
David,
Are you sure that's not caffeine withdrawal?
--
Geoff Wass [dBVIPS]
Montréal, Québec, Canada
.|.|.| dBASE info at
http://geocities.com/geoff_wass |.|.|.
.|.|.| ---------------------------------------------------------- |.|.|.
.|.|.| IT Consultant http://Geoff_Wass.com
|.|.|.
Geoff Wass [dBVIPS]
2008-11-04 05:25:54 UTC
Permalink
Post by David Ball
Hmmm.... it was only 1:14pm. Even with the time change, I
think I was still basking in the sweet warm glow of
well-caffeinated Sunday morning coffee. I may have sadly
bade farewell to my second cup by that time, but the
gloriouos oh-what-a-feeling was still coursing through my
veins. I mean, can't you tell by the inspirational uplifting
tone in my writing?<g>
David,

Indeed I can. You've given me the shakes!
--
Geoff Wass [dBVIPS]
Montréal, Québec, Canada

.|.|.| dBASE info at http://geocities.com/geoff_wass |.|.|.
.|.|.| ---------------------------------------------------------- |.|.|.
.|.|.| IT Consultant http://Geoff_Wass.com |.|.|.
Ronnie MacGregor
2008-11-03 09:14:56 UTC
Permalink
On Sun, 2 Nov 2008 13:14:36 -0500
Post by David Ball
Thanks for that - you've undone years of therapy. The
repressed memories emerge ... the horror ... the horror ...
gaaahhhhhhhhhhhhhhhhhhhhh! <rolling into a fetal position>.
No, I'm not even going to try to decode it. <g>
<LOL>

...... well .... the code's there if you ever want to use it !!
--
Ronnie MacGregor
Scotland

Ronnie at
dBASEdeveloper
dot co dot uk

www.dBASEdeveloper.co.uk
David Ball
2008-11-04 00:21:36 UTC
Permalink
And thank you for that.

By Sunday night, I was looking it over again, and I'm
already considering giving mod_rewrite another try.
Someday.<g>

Thanks again
David Ball
www.ChelseaData.ca
Post by Ronnie MacGregor
...... well .... the code's there if you ever want to use
it !!
--
Ronnie MacGregor
Scotland
Ronnie at
dBASEdeveloper
dot co dot uk
www.dBASEdeveloper.co.uk
Ronnie MacGregor
2008-11-02 16:52:15 UTC
Permalink
On Sun, 2 Nov 2008 09:15:41 -0500
Post by David Ball
<html>
<script type="text/javascript">
<!--
window.location = "index.php"
//-->
</script>
</html>
Hmmmm ...... you did say "low-tech" !! <bg>

Two problems with this approach :

You are relying on client side javascript being switched on for it to work,
.... around 10% of users have it switched off.

Bots don't get educated as to the new file name with a 301.


Here's my .htaccess solution :

######################################
#
# Rewrite *.htm or *.html requests
# to *.php when same name *.php exists
# and flag as permanent move
#
# Ronnie MacGregor
# www.dBASEdeveloper.co.uk
#

RewriteEngine on
RewriteBase /

RewriteRule ^(.*)\.htm$ $1 [NC,C,E=OldType:htm]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [S=1,R=301,L]
RewriteCond %{ENV:OldType} ^htm$
RewriteRule ^(.*)$ $1.htm [L]

RewriteRule ^(.*)\.html$ $1 [NC,C,E=OldType:html]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [S=1,R=301,L]
RewriteCond %{ENV:OldType} ^html$
RewriteRule ^(.*)$ $1.html [L]

#
######################################


Might be a slightly cluncky approach, but it seems to be working fine so far.

Can you decode it ? <g>
--
Ronnie MacGregor
Scotland

Ronnie at
dBASEdeveloper
dot co dot uk

www.dBASEdeveloper.co.uk
Loading...