.htaccess删除扩展名

问题描述 投票:0回答:3

我看到很多关于.htaccess去除扩展名的问题,我找到了一个通过在.htaccess文件中使用这个来去除扩展名中的.php。

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

我的问题是,我的扩展名是my-domainthemessmoothindex.php,在.htaccess文件里有这个扩展名,只会把它缩短为my-domainthemessmoothindex,而其他页面,比如联系我们,看起来就像my-domainthemessmoothcontact。

有没有什么办法可以把中间的扩展名去掉,让它看起来更像。

my-domain/contact
php .htaccess file
3个回答
1
投票

是的,有,但框架,如Symphony,codeigniter等将帮助你做到这一点。如果你正在寻找一个简单的实现,那么你可以做一个重映射的文件名。

$uri = trim($_SERVER['REQUEST_URI'], '');$pages = array( 'contact' => 'path to contactus.php', 'services' => 'path to services.php');if ( in_array($uri, array_keys($pages))){ include $pages[$uri];}。

我没有测试这段代码。总之,你有一个index.php页面,并且这个页面包含了其他页面。


0
投票

你可以在根目录的.htaccess中使用这个规则来隐藏 themes/smooth/.php:

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/themes/smooth/$1\.php -f [NC]
RewriteRule ^(.*)$ /themes/smooth/$1.php [L]
© www.soinside.com 2019 - 2024. All rights reserved.