如何隐藏PHP扩展在.htaccess

编程入门 行业动态 更新时间:2024-10-24 20:14:31
本文介绍了如何隐藏PHP扩展在.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

我试图隐藏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>

的code

我已经尝试了许多不同的差异我在网上找到,但仍然没有运气。 .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 ^([^/]+)/$ example/folder/$1 [R=301,L] # Redirect external .php requests to extensionless url RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ RewriteRule ^(.+)\.php$ example/folder/$1 [R=301,L] # Resolve .php file for extensionless php urls RewriteRule ^([^/.]+)$ $1.php [L]

另见:这个问题

更多推荐

如何隐藏PHP扩展在.htaccess

本文发布于:2023-10-31 18:39:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546943.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PHP   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!