将所有页面请求路由到PHP文件 [英] Routing all page requests to a PHP file
问题描述
我有一个非常简单的网站结构,每个页面都有一个单独的html文件。
https://test.com/page1
https://test.com/page2
https://test.com/page3
这些在最终文件之前可以包含任意数量的子文件夹;
https://test.com/something/something-else/page4
但是,我需要动态生成这些HTML文件。这意味着我需要PHP文件来回显HTML内容,但同时我想删除磁盘上的整个文件结构。我的想法是将请求的页面重新路由到一个PHP文件,该文件与相应的内容相呼应。
例如:
https://test.com/something/something-else/page4?example_get_data=whatever
应该在后台而不是浏览器中显示:
https://test.com/find.php?path=something%2Fsomething-else%2Fpage4%3Fexample_get_data%3Dwhatever
所以我要写一个.htaccess文件,但它没有正确传递路径:
RewriteEngine On
RewriteBase /
RewriteRule ^(。+)$ find.php?path = $ 1 [L,B]
我选择了这些标志,因为:
•不应该考虑过这条规则
•我希望B能够正确地逃脱这条道路,但事实并非如此。
我的尝试:
------ -------------------------------------------------- ----
find.php?path =
1 [L,B]
我选择了那些旗帜是因为:
•不应该考虑过这条规则
•我希望B能逃脱路径不错,但事实并非如此。
我的尝试:
---------------------------------------------- --------------
Hi,
I have quite a simple site structure, with each page having a separate html file.
https://test.com/page1
https://test.com/page2
https://test.com/page3
These can have any number of subfolders before the final file;
https://test.com/something/something-else/page4
However, I need to dynamically generate these HTML files. That means I need PHP files to echo the HTML content, but at the same time I'd like to remove the whole file structure on the disk. My idea is to re-route the requested pages to a single PHP file, which echoes the corresponding content.
So for example:
https://test.com/something/something-else/page4?example_get_data=whatever
should become, in the background and NOT shown in the browser:
https://test.com/find.php?path=something%2Fsomething-else%2Fpage4%3Fexample_get_data%3Dwhatever
So I got to writing a .htaccess file, but it's not passing the path properly:
RewriteEngine On RewriteBase / RewriteRule ^(.+)$ find.php?path=$1 [L,B]
I've chosen those flags because:
• Nothing past this rule should be considered
• I was hoping B would escape the path properly, but it doesn't.
What I have tried:
------------------------------------------------------------
find.php?path=
1 [L,B]
I've chosen those flags because:
• Nothing past this rule should be considered
• I was hoping B would escape the path properly, but it doesn't.
What I have tried:
------------------------------------------------------------
这篇关于将所有页面请求路由到PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!