Forum Moderators: phranque

Message Too Old, No Replies

Multiviews

Mod_rewrite for multiviews

         

manjum66

1:08 am on Nov 21, 2006 (gmt 0)

10+ Year Member



Hello,

I have a hosting where Multiviews are not supported, can any one please provide me the mod_rewrite code to acomplish the mulitview task.

Thanks!
Manju

jdMorgan

1:34 am on Nov 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have a very short list of candidate file extensions, then this can be done. Otherwise, you might want to consider passing control to a script using RewriteMap, and let the script look up the best candidate for a matching file.

If you want to post again and define more precisely what specific functions you need, we might be able to provide a better answer.

Jim

manjum66

9:14 pm on Nov 21, 2006 (gmt 0)

10+ Year Member



Hello Jim,

For ex.. domain test.com and in the web directory we have several HTML files with names test.html, name.html, place.html etc (all the files end with .html). Now anyone access the file using [test.com...] --> the browser should show the file [test.com...] .
[test.com...] ---> [test.com...] like wise

Is that can be done?

Thanks!
Manju

jdMorgan

9:38 pm on Nov 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Something as simple as this in your .htaccess file might work, then:

# IF requested URL has no filetype or ending slash
# RewriteCond $1 !(\.[a-z0-9]+¦/)$ [NC]
# AND IF requested URL resolves to a non-existent file
RewriteCond %{REQUEST_FILENAME} !-f
# AND IF file exists after ".html" is appended
RewriteCond %{REQUEST_FILENAME}.html -f
# THEN rewrite the requested URL to an .html file
RewriteRule (.+) /$1.html [L]

Replace the broken pipe "¦" character in the first RewriteCond pattern above with a solid pipe character from your keyboard before use; Posting on this forum modifies the pipe character.

I assume you already have an .htaccess file in that directory with working rules in it. If not, then you may need to add all or some of these lines ahead of the code above:


Options +FollowSymLinks
RewriteEngine on

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim