Remove .php from urls with htaccess

前端 未结 5 1693
抹茶落季
抹茶落季 2020-11-27 04:20

EDIT: current .htaccess file:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension snippet

# To          


        
5条回答
  •  甜味超标
    2020-11-27 04:48

    Try this code for hiding .php (will work both ways):

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    ## don't touch /forum URIs
    RewriteRule ^forums/ - [L,NC]
    
    ## hide .php extension snippet
    
    # To externally redirect /dir/foo.php to /dir/foo
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^ %1 [R,L]
    
    # To internally forward /dir/foo to /dir/foo.php
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*?)/?$ $1.php [L]
    

提交回复
热议问题