0

私はCodeIgniterを使用してPHPアプリを作成していますが、このプロジェクトには実際には3つのサブアプリがあるため、アプリごとに3つの個別のインデックスファイルがあります。これらのアプリには3つの異なるサブドメインを使用するつもりです。最後に、プロジェクトは私のApacheドキュメントルートのサブディレクトリの下にあります。

したがって、たとえば、このユーザーURLは次のようにマップする必要があります

http://app1.example.com/ABC -----> http://app1.example.com/ext/app1.php/ABC
http://app2.example.com/DEF -----> http://app2.example.com/ext/app2.php/DEF
http://app3.example.com/XYZ -----> http://app3.example.com/ext/app3.php/XYZ

app4やapp5のように、ルールを適用したくないアプリは他にもあります。

私は以前に書き換えルールを使用して作成しましたが、それらはかなり単純であり、これを解読することはできません。.htaccessで次のものを使用しました。たとえば、app1にアクセスしようとすると、URLはになりhttp://app1.example.com/ext/app1.php/ext/app1.php/ext/app1.php/{manytimes}ます。

だから、それはループになっています。

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^app1\.example\.com$
RewriteRule ^ http://app1.example.com/example/app1.php%{REQUEST_URI} [L]
RewriteCond %{HTTP_HOST} ^app2\.example\.com$
RewriteRule ^ http://app2.example.com/example/app2.php%{REQUEST_URI} [L]
RewriteCond %{HTTP_HOST} ^app3\.example\.com$
RewriteRule ^ http://app3.example.com/example/app3.php%{REQUEST_URI} [L]

したがって、実際のサブドメインは-api、viewer、studioであり、それらの最後に実際にはシーケンスがありません。

私の最近の試みは:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(viewer|api|studio)\.example\.com$
RewriteRule ^/(.*)\.example\.com/(.*) http://$1.example.com/ext/$1.php/$2 [L]
4

1 に答える 1

0

拡張機能を使用しない場合は、次の.phpようなことができるはずです。

RewriteEngine On
RewriteBase /

# For app1 through app3.example.com
RewriteCond %{HTTP_HOST} ^(viewer|api|studio)\.example\.com$
# If the request path does not contain the string (viewer or api or studio).php
RewriteCond %{REQUEST_URI} ! %1\.php
# Re-write it to go to the appropriate app
RewriteRule ^.*$ /ext/%1.php%{REQUEST_URI} [L]
于 2012-06-22T03:51:52.507 に答える