删除文件扩展名htaccess的不工作文件扩展名、工作、htaccess

2023-09-02 20:32:23 作者:Be cynical 玩世不恭

以下code工作不删除文件扩展名的.php

the following code is not working to remove the file extension .php

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]

我的网址无法从例如/ about.php 更改为 example.com/about

推荐答案

我已经找到了答案。其工作。在code是如下重写和重定向的URL

I have found the answer. Its working. the code is as follows to rewrite and redirect the url

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

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

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]

据重写并重定向的URL。感谢所有为乌拉圭回合的答案。

It rewrites and redirects the URL. Thanks all for ur answers.