Forum Moderators: phranque

Message Too Old, No Replies

Mod-rewrite extension

         

CNibbana

2:00 am on Jun 1, 2004 (gmt 0)

10+ Year Member



Is it possible to rewrite:

/index
/index/
/index.htm

to /index.html without consideration for the file name (i.e. instead of 'index' could be 'contact', etc.)

This is pretty messy, but this is what I have come up with so far:

RewriteRule (.*)^[/¦(\.html?)$] $1\.html

jdMorgan

2:42 am on Jun 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For your given examples, how about:

RewriteRule ^([^/]+)(/?¦\.htm)$ /$1.html [L]

Jim

CNibbana

3:04 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



I can't seem to make this work. For some reason, the rewrite gets caught in an infinite loop when requesting 'anything'.htm?

Forbidden
You don't have permission to access
/index.html.html.html.html.html.html.html.html.html.html.html.html.html.html.html.html.html.html.html.html.html
on this server.

and links with no extension such as 'index' get rewritten as 'index/' and not 'index.html'?

This is assuming a request to 'www.domain.com/index(.htm, /, or blank)'.

CNibbana

3:28 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



I tried to escape the loop with:

RewriteCond %{REQUEST_URI} !^\.(html¦php)

but that's not working either. Every time I start to think I'm beginning to understand mod-rewrite I get a wake-up call like this ;-)

jdMorgan

3:54 pm on Jun 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm...

OK, how about


RewriteRule ^([^/.]+)(/¦\.htm)?$ /$1.html [L]

The trick is in combining the rules -- doing them separately would be simpler, but less efficient.

Jim

gergoe

3:54 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



Use

RewriteCond %{REQUEST_URI}!\.(html¦php)$

...to escape from the loop. You should not put the ^ in front of the pattern since that's for anchnoring the begining-of-line, and you need the end-of-line anchor ($) in this case.

By the way, you don't really need this RewriteCond, if you use the following RewriteRule instead:


RewriteRule ^/([^/[b].[/b]]+)(/?¦\.htm)$ /$1.html [L]
* note the additonal dot in the pattern

Don't forget to change the broken pipes (¦) to a normal pipes (vertical bars) before using this.

CNibbana

6:45 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



Both patterns are working with limited success. For some reason, removing '?' in the second part of the pattern helps to allow simple 'index' to be rewritten to 'index.html' without an error. This pattern will also correctly rewrite 'index/' to 'index.html'.

The only thing that isn't working is 'index.htm' to 'index.html'? I moved the .htm on the other side of the vertical pipe and that didn't help (not that it should, but I'm trying anything)

This is what I'm using currently:

RewriteRule ^([^/.]+)(/¦\.htm)$ /$1.html