【问题标题】:htaccess URL system: Server showing the file instead of controller page if existshtaccess URL 系统:服务器显示文件而不是控制器页面(如果存在)
【发布时间】:2018-01-22 14:45:06
【问题描述】:

尝试使用htaccess 设置一个简单的example/url/system 事物,诚然,我已经很多年没有做过了,并且在文件实际存在之前一切正常,此时它不再重定向到@ 987654323@,它只显示String.php

RewriteEngine On 

RewriteRule    ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$    index.php?vfirst=$1&vsecond=$2&vthird=$3    [NC,L]   
RewriteRule    ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$    index.php?vfirst=$1&vsecond=$2    [NC,L]   
RewriteRule    ^([A-Za-z0-9-]+)/?$    index.php?vfirst=$1    [NC,L] 

我的例子是/users/edit-profile/。在我创建users/edit-profile.php 之前,服务器会将我带到index.php 并显示我的404 page(以及调试确认vfirst - vthird 已设置并正确读取) - 但是一旦我创建了一个空白edit-profile.php ,空白页是所有出现而不是index.php。我已经覆盖了 PHP 以包含 users/edit-profile.php(如果它存在并且是选择的 URL),但我认为它并没有那么远。

Regex/htaccess 从来都不是我的事,但即使我认为它看起来很轻,我也一定错过了一条基本上告诉它忽略文件是否存在、捕获​​变量并转到 index.php 的行。有什么帮助吗?

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    我不确定我是否正确理解了您的问题,但我会尽我所能回答。

    所以,如果你需要显示一些页面,当一个不存在的页面被调用时,然后尝试使用这个脚本:

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

    如果您需要做其他事情,请告诉我们,也许我或其他人会提供必要的信息。

    【讨论】:

    • 对不起,我不清楚。如果我访问说,我得到的 htaccess(带有代码), /test/example/ 它会工作并显示 index.php?vfirst=test&vsecond=example (然后我用它来包含 test/example.php 使用 PHP) -但是,一旦我实际创建 test/example.php,它就不再显示 index.php,它只是尝试打开文件本身。因此,只要文件不存在,我的 htaccess 就可以工作,只要它存在,URL 系统就会被忽略,并且空白页面会自行显示,而不是包含在 index.php 页面中。希望那更清楚一点!不过还是谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 2019-09-25
    • 2021-04-23
    相关资源
    最近更新 更多