使用.htaccess删除.php扩展名,但文件夹访问返回404 [英] Using .htaccess for remove .php extension but folder access returns 404

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

问题描述

我正在使用此.htaccess删除URL中的.php

I'm using this .htaccess for remove .php in my URLs

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

我的文件结构是这样的:

My files structure is this:

css/
es/
-- contact.php
-- index.html
js/
contact.php
index.php

我要创建的是我主index.php中的链接,如下所示:

What I'm trying to create is a link in my main index.php like this:

<a href="es/">Español</a>

但是当我尝试访问它时,服务器返回404错误。当我删除.htaccess时,此链接可以正常工作,因此我想我需要在.htaccess中添加其他内容。有人可以指导我我要添加些什么才能使它正常工作吗?

But when I try to access it, my server returns a 404 error. When I delete the .htaccess, this link works fine, so I guess that I need something else in the .htaccess. Can anybody please guide me on what do I have to add for this to work?

推荐答案

带有php测试,没有文件夹:

With test for php and without folder:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

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

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