PHP/.htaccess: removing php extension from url

前端 未结 2 1432
暖寄归人
暖寄归人 2020-12-22 01:55

I was using .htaccess code to remove .php extension for all my web pages. Here\'s the code I use:

RewriteEngine On
RewriteCond /%{REQUEST_FILENAME}.php -f
Re         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-22 02:32

    It seems like the slash at the end of your rule might be there, or it might not. Adding a ? makes it optional, so that mysite.com/about and mysite.com/about/ will both match.

    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9_-\s]+)/?$ /$1.php
    

    It's hard to say if this is what's causing your problem, or if something else is, though. Does mysite.com/about.php also give you an error?

提交回复
热议问题