Forcing the rewriting of URLs by hiding .php AND .htm(l) extensions and redirecting to extensionless URLs

前端 未结 2 1259
再見小時候
再見小時候 2021-01-26 15:18

here is my configuration:

  • http://domain.com (obviously fictitious name...) hosted on a server running Apache with mod_rewrite enabled
  • folder named \"foo\"
2条回答
  •  耶瑟儿~
    2021-01-26 16:11

    I would like thank Everybody for this post as it really helped me a lot and I used something like the one below and works for me ...

    Options +FollowSymLinks  -MultiViews
    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{ENV:REDIRECT_END}  =1
    RewriteRule ^ - [L,NS]
    
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^(.*?)\.(php|html?)$        $1   [R=301,NC,NS]
    
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule (.*)$ $1.html   [L,E=END:1,NS]
    
    RewriteCond %{REQUEST_FILENAME}\.htm -f
    RewriteRule (.*)$ $1.htm    [L,E=END:1,NS]
    
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule (.*)$ $1.php    [L,E=END:1,NS]
    

    This version works for me.

    Thank you.

    Cheers!

提交回复
热议问题