我一直在寻找一种方法将文件从我的根文件夹/
移动到指定文件夹/newFolder
,同时将此更改隐藏在用户之外,例如,当转到
http://site.com/ABC
我希望浏览器显示来自
的内容http://site.com/customerPages/ABC
但客户端会在浏览器中看到以下网址:
http://site.com/ABC
我尝试过使用RewriteRule
,但由于文件夹名称未预先定义,因此无法执行此操作。然后我尝试在我的404页面中使用file_get_contents()
,但它打破了所有相对路径。
最后,我在404页面中使用了以下代码:
// Redirect customers to customers landing pages under /newFolder
if (strpos($message,'newFolder') === false) {
$url = 'http://'.$_SERVER['HTTP_HOST'].'/newFolder'.$message;
echo '<frameset><frame src="/newFolder'.$message.'"></frameset>';
exit();
} else {
// correct the URL - remove the `/newFolder` bit
$message = str_replace('/newFolder','',$message);
}
$ message - 请求的URI
我知道这个解决方案很脏,我很乐意改进它。谁知道怎么做?
我的设计有问题吗?使用frameset
显示网页时是否有任何问题?
修改
我最终坚持使用原始解决方案(使用带有框架集的404页面),以避免为所有页面创建规则,并使.htaccess
更重。
答案 0 :(得分:1)
如果您希望为您的客户提供不同的网址
您可以在htaccess中使用此代码
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)/ABC/(.*?)/(.*)
RewriteRule ^ customerPages/%3 [L]
我在我的网站主机中测试它正常工作
样品: 虚拟URL
http://sepidarcms.ir/ABC/Client1/image/logo.png
http://sepidarcms.ir/ABC/Client2/image/logo.png
http://sepidarcms.ir/ABC/Client3/image/logo.png
所有人的真实网址:
http://sepidarcms.ir/customerPages/image/logo.png
如果你想在此代码中稍微改变一下就可以删除ABC
答案 1 :(得分:0)
实际上,我从未使用过cakePHP,但这对我有用;
文件/文件夹;
./
index.php
images/
so-logo.png
newfolder/
abc.php
目录;
// .htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ newfolder/$1.php [L]
// index.php
<? echo __file__; ?>
<br>
<img src="images/so-logo.png" width="100">
// abc.php
<? echo __file__; ?>
网址的输出;
// index.php - http://localhost/rewrite/
D:\LAMP\www\rewrite\index.php
[logo]
// abc.php - http://localhost/rewrite/abc
D:\LAMP\www\rewrite\newfolder\abc.php