【发布时间】: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