You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by François Beausoleil <fr...@teksol.info> on 2008/10/15 18:29:39 UTC
[users@httpd] Rewriting URLs to remove .html extension
Hi all!
I moved my blog from a CMS to plain files. My old links are of the
form:
http://blog.teksol.info/tags/unit-testing
All files are now stored with a .html extension, such that
%{DOCUMENT_ROOT}/tags/unit-testing.html
is an existing file.
I found a thread in 2004 which talked about this problem:
http://mail-archives.apache.org/mod_mbox/httpd-users/200410.mbox/%3C416E8250.2040504@zetnet.co.uk%3E
The URL Rewriting Guide's Canonical URLs example is also similar to
this.
I can't seem to make things work. Here's my .htaccess:
# ------------------
RewriteEngine on
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA,L]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [QSA,L]
# Rewrite X.html to X only
#RewriteRule ^(.*)\.html$ $1 [R=301,L]
# ------------------
I'm reading my first rule as "Rewrite / to /index.html" and end there.
My second rule is supposed to read "If there exists a file named
X.html, rewrite to that and end", but it doesn't work. When I ask
for /tags/unit-testing, I get a 404.
The third rule (which is commented out) is supposed to rewrite X.html
to X. But when I have that enabled, requests without a .html
extension end up in an infinite redirection loop for the 404 page.
This is hosted on DreamHost and I can't active the rewrite log. If I
had the log, I would probably be able to fix my problem myself!
I'm pretty sure my error is simple. If anybody had a quick pointer,
I'd really appreciate.
Thanks!
--
François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Rewriting URLs to remove .html extension
Posted by Nick Kew <ni...@webthing.com>.
On 15 Oct 2008, at 17:29, François Beausoleil wrote:
> Hi all!
>
> I moved my blog from a CMS to plain files. My old links are of the
> form:
>
> http://blog.teksol.info/tags/unit-testing
>
> All files are now stored with a .html extension, such that
>
> %{DOCUMENT_ROOT}/tags/unit-testing.html
>
> is an existing file.
Stop right there, and read about multiviews!
> The URL Rewriting Guide's Canonical URLs example is also similar to
> this.
As in so many cases, anything involving mod_rewrite is unnecessarily
complex.
--
Nick Kew
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Rewriting URLs to remove .html extension
Posted by Brian Mearns <me...@gmail.com>.
It looks like %{REQUEST_FILENAME} is the /full/ system path to the
file, so I think the %{DOCUMENT_ROOT} is incorrect there. I'm not
familiar with RewriteCond's, but personally I would try removing the
DOCUMENT_ROOT from that condition.
Good luck.
-Brian
On Wed, Oct 15, 2008 at 12:29 PM, François Beausoleil
<fr...@teksol.info> wrote:
> ...
> RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}.html -f
> RewriteRule ^(.*)$ $1.html [QSA,L]
> ...
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org