插入第二个域规则 htaccess
Insert second domain rules htaccess
我购买了第二个域并将其添加到我的主机中,如何配置 htaccess 文件以将第二个域的页面重定向到它自己的文件夹?
这是我当前的文件,第一个域在 public 文件夹中:
RewriteEngine on
RewriteRule ^sitemap/sitemap-surveys.xml$ sitemap/sitemap-surveys.php
RewriteRule ^sitemap/sitemap-users.xml$ sitemap/sitemap-users.php
RewriteRule ^sitemap/sitemap-flashpinions.xml$ sitemap/sitemap-flashpinions.php
RedirectMatch ^/$ /accounts/index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/about/index.html$
RewriteRule ^.*$ /public/index.php [NC,L,QSA]
第二个域位于 site2 文件夹内
根据您显示的示例,您能否尝试以下操作。考虑到任何拥有您的新域的 url 都应由 site2/public/index.php 文件重写,请确保您的 htaccess 应位于 htaccess、site2 文件夹和 site1 文件夹所在的同一文件夹中.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(site2)\.com$ [NC]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^ %1/public/index.php [L]
RewriteRule ^sitemap/sitemap-surveys.xml$ sitemap/sitemap-surveys.php
RewriteRule ^sitemap/sitemap-users.xml$ sitemap/sitemap-users.php
RewriteRule ^sitemap/sitemap-flashpinions.xml$ sitemap/sitemap-flashpinions.php
RewriteCond %{HTTP_HOST} !^(site2)\.com$ [NC]
RewriteRule ^/?$ /accounts/index [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/about/index.html$
RewriteRule ^.*$ /public/index.php [NC,L,QSA]
我是如何测试上面的(我在这里使用本地主机,你可以在这里使用你的域名),我的文件夹位置是怎样的。
/var/www/html/.htaccess
/var/www/html/site2/
/var/www/html/site2/public/index.php
检测结果:
curl -IL "http://localhost:80/test/blabla"
HTTP/1.1 200 OK
我购买了第二个域并将其添加到我的主机中,如何配置 htaccess 文件以将第二个域的页面重定向到它自己的文件夹? 这是我当前的文件,第一个域在 public 文件夹中:
RewriteEngine on
RewriteRule ^sitemap/sitemap-surveys.xml$ sitemap/sitemap-surveys.php
RewriteRule ^sitemap/sitemap-users.xml$ sitemap/sitemap-users.php
RewriteRule ^sitemap/sitemap-flashpinions.xml$ sitemap/sitemap-flashpinions.php
RedirectMatch ^/$ /accounts/index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/about/index.html$
RewriteRule ^.*$ /public/index.php [NC,L,QSA]
第二个域位于 site2 文件夹内
根据您显示的示例,您能否尝试以下操作。考虑到任何拥有您的新域的 url 都应由 site2/public/index.php 文件重写,请确保您的 htaccess 应位于 htaccess、site2 文件夹和 site1 文件夹所在的同一文件夹中.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(site2)\.com$ [NC]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^ %1/public/index.php [L]
RewriteRule ^sitemap/sitemap-surveys.xml$ sitemap/sitemap-surveys.php
RewriteRule ^sitemap/sitemap-users.xml$ sitemap/sitemap-users.php
RewriteRule ^sitemap/sitemap-flashpinions.xml$ sitemap/sitemap-flashpinions.php
RewriteCond %{HTTP_HOST} !^(site2)\.com$ [NC]
RewriteRule ^/?$ /accounts/index [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/about/index.html$
RewriteRule ^.*$ /public/index.php [NC,L,QSA]
我是如何测试上面的(我在这里使用本地主机,你可以在这里使用你的域名),我的文件夹位置是怎样的。
/var/www/html/.htaccess
/var/www/html/site2/
/var/www/html/site2/public/index.php
检测结果:
curl -IL "http://localhost:80/test/blabla"
HTTP/1.1 200 OK