删除url中的.php

删除url中的.php,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我在我的网络主机的子文件夹中有一个网站。现在我想从url中删除.php 我现在有这个.htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /sub-folder/ # remove index.php from URLs RewriteCond %{THE_REQUEST} /index\.php [NC] RewriteRule ^(.*?)index\.php$ $1 [L,R=302,NC,NE]

我在我的网络主机的子文件夹中有一个网站。现在我想从url中删除.php

我现在有这个.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sub-folder/

# remove index.php from URLs
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ $1 [L,R=302,NC,NE]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

重新启动发动机
重写基本/子文件夹/
#从URL中删除index.php
RewriteCond%{THE_REQUEST}/index\.php[NC]
重写规则^(.*)索引\.php$$1[L,R=302,NC,NE]
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则。index.php[L]
索引工作正常。但是对于其他页面,比如contact.php、about.php等,我该如何解决这个问题呢。我是否必须像在我的.htaccess中添加所有index.php一样添加它,或者如何添加?请帮忙:)

谢谢

此规则正下方:

RewriteRule ^index\.php$ - [L]
尝试添加:

RewriteCond %{THE_REQUEST} \ /+([^\?]+)\.php
RewriteRule ^ /%1 [L,R=301]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule ^(.*)$ $1.php [L]

是的,他们让我为我尝试过的所有页面编制索引。如果我尝试www.mysite.com/sub-folder/我会得到索引。如果我尝试使用www.mysite.com/sub-folder/about作为索引,那么对于这些页面,我最终需要编写.php。。