开发者

.htaccess instructions conflict "DocumentRoot change" + "always display subdomain"

开发者 https://www.devze.com 2023-01-30 13:05 出处:网络
I have a rewrite that changes my DocumentRoot from /public_html to /public_html/MAIN and it works great.

I have a rewrite that changes my DocumentRoot from /public_html to /public_html/MAIN and it works great.

RewriteRule ^$ /MAIN/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/MAIN/
RewriteRule ^(.*)$ /MAIN/$1

Now If I try to add the following instruction to always show the www subdomain, it no longer behaves properly...

RewriteCond %{http_host} ^domain.com [nc]  
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Visiting http://domain.com/ causes a rewrite to http://www.domain.com/M开发者_运维百科AIN/ which is not what I want. I do not want the MAIN subdirectory to be visible.

What am I missing?


The ^(.*)$ pattern captures the current URI, no matter it's in the location bar or it's an internal redirection. One of these solutions should work:

  • Put the subdomain redirection first
  • Replace $1 with a variable, e.g. %{REQUEST_URI}
0

精彩评论

暂无评论...
验证码 换一张
取 消