Remove .php extension with .htaccess

前端 未结 15 2545
一生所求
一生所求 2020-11-21 04:32

Yes, I\'ve read the Apache manual and searched here. For some reason I simply cannot get this to work. The closest I\'ve come is having it remove the extension, but it point

15条回答
  •  生来不讨喜
    2020-11-21 04:55

    Here is the code that I used to hide the .php extension from the filename:

    ## hide .php extension
    # To redirect /dir/foo.php to /dir/foo
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^ %1 [R=301,L,NC]
    

    Note: R=301 is for permanent redirect and is recommended to use for SEO purpose. However if one wants just a temporary redirect replace it with just R

提交回复
热议问题