nul*_*ter 11 php .htaccess cakephp
在SO中尝试过很多例子,但似乎都没有.考虑一下我的设置:
/public_html/
/app/
/cgi-bin/
/lib/
/plugins/
/revamp/
/vendors/
Run Code Online (Sandbox Code Playgroud)
我目前有一个cakephp网站site.com
,其文件位于/app/
文件夹下,我现在使用的.htaccess看起来像这样:
<IfModule mod_rewrite.c>
RewriteEngine on
ReWriteRule ^$ app/webroot/ [L]
ReWriteRule (.*) app/webroot/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
我想将子域重定向revamp.site.com
到/revamp/
另一个cakephp站点的文件夹.
被要求创建一个vhost,我做了,它被设置为子域文件夹,我想要的帮助是htaccess规则适用于上述一个,如果请求的地址之前有子域,也可以重定向到子域域名......
以下内容.htaccess
将我带到我的子域,但仅限于index.html
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site\.com$
RewriteRule (.*) app/webroot/$1 [L]
RewriteCond %{HTTP_HOST} ^revamp\.site\.com$
RewriteRule (.*) revamp/index.html [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
它是两个答案的混合......虽然我放在子域中的路径,它只会让我到index.html(因为它在htaccess中是硬编码的).尝试也 revamp/$
并 revamp/$1
没有运气.
尝试编辑第一个答案:
<IfModule mod_rewrite.c>
RewriteEngine on
#subdomain simple site
RewriteCond %{HTTP_HOST} ^subdomain\.test\.com$
RewriteCond %{REQUEST_URI} !^/subdomain
RewriteRule ^(.*)$ subdomain/$1 [L]
#cakephp site
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
仍然给出500,我也尝试切换两个块的位置
工作解决方案,在/public_html/app
和下有两个cakephp网站/public_html/revamp/app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^revamp\.site\.com$
RewriteRule ^(.*)$ revamp/app/webroot/$1 [NC,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [NC,L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
您可以通过针对不同的域使用“重写条件”来实现所需的重写:
在我的机器上,我创建了一个文件夹结构,例如
public_html
-app
-webroot
-local
-app
-webroot
Run Code Online (Sandbox Code Playgroud)
文件夹中的 app、webroot 和本地目录public_html
,然后本地文件夹中的 app 和 webroot 目录。
现在我创建了一个虚拟主机条目,如下所示:
<VirtualHost test.com:80>
ServerName test.com
ServerAlias local.test.com
DocumentRoot /var/www/html/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
意思test.com
是 和local.test.com
都指向public_html
目录。
现在您的目标是,如果域是test.com
那么外部应用程序应该运行,如果域是那么local.test.com
您的内部(本地文件夹)应用程序应该运行。
.htaccess
作为cakephp的结构,我将.htaccess
文件放置在两个应用程序的app
文件webroot
夹中。
目录.htaccess
中的代码app/
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
的代码.htaccess
在webroot/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
.htaccess
现在根目录的更改即public_html
:
<IfModule mod_rewrite.c>
RewriteEngine on
#for test.com
RewriteCond %{HTTP_HOST} ^test\.com$
RewriteRule ^(.*)$ app/webroot/$1 [NC,L]
#for local.test.com
RewriteCond %{HTTP_HOST} ^local\.test\.com$
RewriteRule ^(.*)$ local/app/webroot/$1 [NC,L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
%{HTTP_HOST} ^test\.com$
将识别该域是test.com
%{HTTP_HOST} ^local\.test\.com$
将识别该域是local.test.com
对于一般的子域重写,您可以使用以下代码:
文件夹结构:
public_html
-index.html
-subdomain
--index.html
Run Code Online (Sandbox Code Playgroud)
代码.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
#for subdomain.test.com
RewriteCond %{HTTP_HOST} ^subdomain\.test\.com$
RewriteCond %{REQUEST_URI} !^/subdomain
RewriteRule ^(.*)$ subdomain/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
现在 test.com 将打开文件index.html
夹public_html
,同时subdomain.test.com
将打开index.html
文件subdomain
夹
更新答案2
我创建了问题中提到的确切目录结构,下面的 htaccess 代码对我有用:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test\.com$
RewriteRule ^(.*)$ app/webroot/$1 [NC,L]
RewriteCond %{HTTP_HOST} ^revamp\.test\.com$
RewriteCond %{REQUEST_URI} !^/revamp
RewriteRule ^(.*)$ revamp/$1 [NC,L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1008 次 |
最近记录: |