如何在 .htaccess 中隐藏 .php 扩展名

问题描述:

可能的重复:
使用 .htaccess 删除 .php 扩展名

我试图隐藏 .php 文件扩展名,但由于某种原因无法让它工作.我最近的尝试如下:

I'm trying to hide the .php file extension but for some reason can't get it to work. My latest attempt was the following:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^folder/([a-zA-Z_-0-9]+)/?$ /folder/$1.php
</IfModule>

我在网上找到了许多不同的代码变体,但仍然没有运气..htaccess 文件放在根目录中.

I have tried many different variances of code I have found online but still no luck. The .htaccess file is placed within the root directory.

我用过这个:

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]

# Redirect external .php requests to extensionless URL
RewriteCond %{THE_REQUEST} ^(.+).php([#?][^ ]*)? HTTP/
RewriteRule ^(.+).php$ http://example.com/folder/$1 [R=301,L]

# Resolve .php file for extensionless PHP URLs
RewriteRule ^([^/.]+)$ $1.php [L]

另见:这个问题