【发布时间】:2019-08-10 08:43:47
【问题描述】:
我想重定向每个请求:
http://example.com/page1.php (<-non-existent url to file)
到
http://example.com/content/sites/page1.php (<-real path to file in folder structure)
在继续展示的同时:
http://example.com/page1.php
在浏览器中并使用位于根文件夹中的 .htaccess 文件。
这有可能吗?在此先感谢:)
【问题讨论】:
-
粘贴你在 htaccess 中所做的事情
-
@MohammedElhag 到目前为止,我只有文件扩展名代码:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php -
是的,这正是 URL 重写的工作原理。您应该考虑使用路由器(将所有内容发送到 index.php 并从那里分派)
-
@LarsStegelitz 我最初的想法是将每个不存在的 url(由 history.pushstate() 生成)重定向到 index.php,内容通过 ajax 加载
-
是的,没错,大型框架就是这样做的:物理上不存在的所有内容(可从网络访问)都通过 index.php 进行路由