Reputation: 17846
I was looking for a way to move files from my root folder /
to designated folder /newFolder
while weeping this change hidden from users, for example, when going to
http://site.com/ABC
I want the browser to display content from
http://site.com/customerPages/ABC
but the client will see the following URL in his browser:
http://site.com/ABC
I've tried using RewriteRule
but since the folder names aren't pre-defined I failed to do so. Then I tried using file_get_contents()
in my 404 page but it broke all the relative paths.
Finally I used the following code in my 404 page:
// 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 - the requested URI
I know that this solution is dirty, and i would love to improve it. Anyone knows how to?
Are there any problems with my design? are there any issues using frameset
to display a webpage?
EDIT
I eventually stayed with my original solution (used the 404 page with frameset) to avoid from creating rules for all of the pages, and there for making the .htaccess
heavier.
Upvotes: 0
Views: 98
Reputation: 3149
If You Want have Different URL for Your client
You Can Use This code in htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)/ABC/(.*?)/(.*)
RewriteRule ^ customerPages/%3 [L]
I Test It In My Web host Work correctly
Sample: Virtual 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
Real URL For All:
http://sepidarcms.ir/customerPages/image/logo.png
if You Want Can Remove ABC With a Little Change In This code
Upvotes: 1
Reputation: 11586
Actually, I have never used cakePHP, but this worked for me;
Files/folders;
./
index.php
images/
so-logo.png
newfolder/
abc.php
Contents;
// .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__; ?>
URL's outputs;
// 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
Upvotes: 0