【问题标题】:Using .htaccess for remove .php extension but folder access returns 404使用 .htaccess 删除 .php 扩展名,但文件夹访问返回 404
【发布时间】:2017-08-27 15:33:02
【问题描述】:

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

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

我的文件结构是这样的:

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

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

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

但是当我尝试访问它时,我的服务器返回 404 错误。当我删除 .htaccess 时,这个链接可以正常工作,所以我想我需要 .htaccess 中的其他内容。谁能指导我我必须添加什么才能使它起作用?

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    带测试php,不带文件夹:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-14
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      相关资源
      最近更新 更多