使用 .htaccess 重写 URL 以隐藏 PHP 扩展名

Rewrite URL with .htaccess to hide PHP extension(使用 .htaccess 重写 URL 以隐藏 PHP 扩展名)
本文介绍了使用 .htaccess 重写 URL 以隐藏 PHP 扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个问题,我正在为特定应用开发网络服务.上周我将备份从 server1 转移到 server2,因为那一刻我的 .htaccess 将不再工作.

I've a question, I'm developing a webservice for a specific app. Last week I transferred my back-up from server1 to server2, since that moment my .htaccess won't work anymore.

我的网络服务的网址是:http://apps.holtesdesign.nl/inholland/apiv0/

The url for my webservice is: http://apps.holtesdesign.nl/inholland/apiv0/

这个 url 工作正常,加载错误报告模块:http://apps.holtesdesign.nl/inholland/apiv0/bugreport.php

This url works fine, to load the bugreport module: http://apps.holtesdesign.nl/inholland/apiv0/bugreport.php

但网址应该是:http://apps.holtesdesign.nl/inholland/apiv0/bugreport

当您打开最后一个 url 时,您会看到它会导致内部服务器错误.你知道这怎么可能吗?

When you'll open the last url, you'll see that it will result in an internal server error. Do you know how it's possible?

我的 .htaccess 看起来像:

My .htaccess looks like:

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

服务器在 CentOS 上运行,我已经检查过 mod_rewrite 是否正在运行...

The server is running on CentOS, and I've already checked if mod_rewrite is functioning...

我希望你们能帮助我!

干杯,

杰尔默

推荐答案

这将解决它:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.php

<小时>

如果它不起作用,请更正 Wamp 服务器的设置:


If it doesn't work correct the settings of your Wamp Server:

  1. 左键单击 WAMP 图标
  2. 阿帕奇
  3. Apache 模块
  4. 左键单击 rewrite_module.

这篇关于使用 .htaccess 重写 URL 以隐藏 PHP 扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)