【问题标题】:How do I link correctly when a file(extensions removed) and a folder have the same name?当文件(已删除扩展名)和文件夹具有相同名称时,如何正确链接?
【发布时间】:2013-09-26 17:23:25
【问题描述】:

这就是我一直面临的问题。

我必须链接到一个与我服务器上的文件夹同名的文件。通常它不会是一个问题,但由于我已经删除了扩展它一直没有工作。

文件:privacy-policy.php 文件夹:隐私政策

我已经使用 .htaccess 删除了 .php 扩展名,使用我将在下面列出的代码。

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

当我单击链接 hxxp://domain.com/privacy-policy 时,它会将我带到 hxxp://domain.com/privacy-policy/ 这是文件夹。我希望此链接将我带到已删除扩展名的文件 hxxp://domain.com/privacy-policy。

我尝试关闭 DirectorySlash 但它不起作用。

在这方面的任何帮助将不胜感激。 问候, 维尼思·阿尔梅达

【问题讨论】:

    标签: php file .htaccess directory


    【解决方案1】:
    1. 你需要DirectorySlash Off
    2. 先删除RewriteCond

    你的规则是这样的:

    DirectorySlash Off
    
    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php [L]
    

    【讨论】:

    • 感谢您花时间帮助我。我将这些行复制到我的 .htaccess 中,但问题仍然存在。单击该链接仍会将我带到 hxxp://domain.com/privacy-policy/
    • 查看编辑。你也需要DirectorySlash Off。确保在不同的浏览器中进行测试以避免缓存。
    • 成功了!非常感谢阿努巴瓦。从早上起,我就一直在努力寻找解决方案。现在我要逐行研究这些命令的含义。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 2021-11-15
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    相关资源
    最近更新 更多