0

たとえば、次の場合に、この変更をユーザーから隠して泣きながら、ルートフォルダー/から指定されたフォルダーにファイルを移動する方法を探していました。/newFolder

http://site.com/ABC

ブラウザにコンテンツを表示させたい

http://site.com/customerPages/ABC

ただし、クライアントのブラウザには次の URL が表示されます。

http://site.com/ABC

使用してみましRewriteRuleたが、フォルダー名が事前に定義されていないため、失敗しました。次にfile_get_contents()、404ページで使用しようとしましたが、すべての相対パスが壊れました。

最後に、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

このソリューションが汚いことはわかっています。改善したいと思います。誰でも方法を知っていますか?

私のデザインに問題はありますか?framesetWeb ページの表示に問題はありますか?

編集

私は最終的に、すべてのページのルールを作成することを避け、ページを.htaccess重くするために、元のソリューション (フレームセットで 404 ページを使用) にとどまりました。

4

2 に答える 2

1

クライアントに別のURLが必要な場合

このコードはhtaccessで使用できます

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase   /
RewriteCond %{REQUEST_URI} ^(.*)/ABC/(.*?)/(.*)
RewriteRule ^ customerPages/%3 [L]

私は自分のWebホストでそれをテストします正しく動作します

サンプル:仮想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

すべての実際のURL:

http://sepidarcms.ir/customerPages/image/logo.png

このコードを少し変更するだけでABCを削除できます

于 2013-01-20T19:03:35.703 に答える
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__; ?>

URL の出力。

// 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
于 2013-01-20T21:34:32.757 に答える