Rewriteengine in .htaccess to catch files not ending in html

后端 未结 3 412
情书的邮戳
情书的邮戳 2021-01-18 23:34

I\'d like to use mod rewrite in to convert web page addresses like /directory to /directory/index.html, in a standard LAMP hosting situatio

3条回答
  •  太阳男子
    2021-01-19 00:19

    Use a RewriteCond directive to check whether the URL path does not end with a .html:

    RewriteCond %{REQUEST_URI} !\.html$
    RewriteRule ^(.*[^/])?/?$ $1/index.html [L]
    

    Edit   You’re using a look-ahead assertion ((?!…)). But there isn’t anything after .* (only a $). So try a look-behind assertion instead:

    RewriteRule ^.*$(?

    But note that you probably need Apache 2.2 to use these assertions.

提交回复
热议问题