【发布时间】:2018-06-04 19:06:37
【问题描述】:
我现在开始觉得有点傻了。我第一次在没有像 CI 或 Laravel 等已建立的 PHP 框架的情况下工作,并且我遇到了 htaccess 将文件夹路径结构重定向到文件夹中的索引文件的问题。
这是一个例子: 我有四个网址如下:
http://www.example.com <-- this is a WurstPress site - the client's choice, not mine)
http://www.example.com/user <-- "user" is an actual folder with an index.php file in it
http://www.example.com/user/settings/private
http://www.example.com/user/settings/public
问题是我可以在根目录下访问 WP 站点,并且可以访问 /user url 没问题。但是我想将这两个设置 url 重写到包含完整 url 路径的 /user/index.php 文件中,就像 CI 或 Laravel 一样,这样我就可以获得 url 的片段,如下所示:http://www.example.com/user/index.php/settings/private 我不想将用户重定向到那里,但我需要 index.php 脚本来查看请求 uri 并查看 /user/index.php/settings/private 路径。
我已经为此苦苦挣扎了太久,我知道这是我没有看到的愚蠢简单的事情,所以在这里感谢大家的帮助。
这是我的 .htaccess 文件:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^/user/(.*) /user/index.php$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
请记住,我不能关闭客户的 WP 站点,所以我不能更改基本路径,我也需要将 WP 的东西留在那里。我在上面添加了我的代码。对于用户路径,我已经尝试了可能有一百种或更多种不同的组合。
在我的 user/index.php 文件中,我现在只是尝试输出请求 URI,但我只是得到了 WP page not found 页面。
【问题讨论】:
标签: php .htaccess mod-rewrite