从 URL 中隐藏 PHP 文件扩展名 [英] Hide PHP file extension from the URL

查看:78
本文介绍了从 URL 中隐藏 PHP 文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我网站的内容存储在数据库中.它就像一个 CMS.从管理面板添加页面内容,内容将存储在数据库中.

I am storing my website's content in a database. It is like a CMS. One will add page content from an admin panel, and content will stored in the database.

在一页中,我添加了 10-12 个链接作为 <a href="page.php/abc" 并且我的 URL 看起来像 www.example.com/page.php/abc.我想从 page.php 隐藏 .php.如何在不使用 .htaccess 的情况下执行此操作?

In one page, I have added 10-12 links as <a href="page.php/abc" and my URLs looks like www.example.com/page.php/abc. I want to hide .php from page.php. How can I do this without using .htaccess?

我尝试过使用 str_replace(添加到来自 CMS 的页面内容中),但它似乎无法将其识别为 PHP 代码并将其视为字符串.

I have tried with str_replace (added in page content from the CMS), but it seems like it does not recognise it as PHP code and take it as a string.

推荐答案

您可以通过以下方式进行:

You can do this in the following way:

或者将此代码放入您的 htaccess 文件(您不需要), 或将此代码放在您服务器的配置文件中:

Either put this code in your htaccess file (which you don't want), or put this code in your server's configuration file:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.php -f
  RewriteRule ^(.*)$ $1.php
</IfModule>

这会在您网站的所有 URL 中隐藏 .php.

This will hide .php from all URLs of your website.

就是这样.

这篇关于从 URL 中隐藏 PHP 文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆