使用 .htaccess 删除 .php 扩展名 [英] Remove .php extension with .htaccess

查看:37
本文介绍了使用 .htaccess 删除 .php 扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我已经阅读了 Apache 手册并在此处进行了搜索.出于某种原因,我根本无法让它发挥作用.我最接近的是让它删除扩展名,但它指向根目录.我希望它只在包含 .htaccess 文件的目录中工作.

Yes, I've read the Apache manual and searched here. For some reason I simply cannot get this to work. The closest I've come is having it remove the extension, but it points back to the root directory. I want this to just work in the directory that contains the .htaccess file.

我需要对 .htaccess 文件做三件事.

I need to do three things with the .htaccess file.

  1. 我需要它来删除 .php

一个.我有几个使用选项卡的页面,URL 看起来像 page.php#tab - 这可能吗?

a. I have several pages that use tabs and the URL looks like page.php#tab - is this possible?

B.我有一个页面使用附加到 URL 的会话 ID 来确保您来自正确的位置,www.domain.com/download-software.php?abcdefg.

b. I have one page that uses a session ID appended to the URL to make sure you came from the right place, www.domain.com/download-software.php?abcdefg.

这可能吗?同样在这样做时,我是否需要从标题导航包含文件中的链接中删除 .php ?IE 是否应该support"是<a href="support">support</a>?

Is this possible? Also in doing this, do I need to remove .php from the links in my header nav include file? Should IE "<a href="support.php">support</a>" be <a href="support">support</a>?

  1. 我希望它在每个 URL 之前强制 www,所以它不是 domain.com,而是 www.domain.com/page.
  2. 我想从页面中删除所有尾部斜杠.
  1. I would like it to force www before every URL, so it's not domain.com, but www.domain.com/page.
  2. I would like to remove all trailing slashes from pages.

我会继续寻找、尝试等等.在子目录中会导致任何问题吗?

I'll keep looking, trying, etc. Would being in a sub directory cause any issues?

推荐答案

Gumbo 在 Stack Overflow 问题中的回答 如何使用 Apache mod_rewrite 隐藏 .html 扩展名 应该可以正常工作.

Gumbo's answer in the Stack Overflow question How to hide the .html extension with Apache mod_rewrite should work fine.

重新 1) 将 .html 更改为 .php

Re 1) Change the .html to .php

Re a.) 是的,这是可能的,只需将 #tab 添加到 URL.

Re a.) Yup, that's possible, just add #tab to the URL.

Re b.) 可以使用 QSA(查询字符串追加),见下文.

Re b.) That's possible using QSA (Query String Append), see below.

应该也适用于子目录路径:

This should also work in a sub-directory path:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*.php$ %{REQUEST_FILENAME}.php [QSA,L]

这篇关于使用 .htaccess 删除 .php 扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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