开发者

Parked domain redirect to subfolder

开发者 https://www.devze.com 2023-03-17 17:10 出处:网络
I have 2 domain: maindomain.com parkeddomain.com Before having the parkeddomain.com domain, my .htaccess was:

I have 2 domain:

  • maindomain.com
  • parkeddomain.com

Before having the parkeddomain.com domain, my .htaccess was:

RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Now that I have the new domain, I want to redirect the visits in a subfolder: /park/ So basically, if the following URI would display the exact same page:

  • http://www.maindomain.com/park/
  • http://www.parkeddomain.com/

My attempt to make a .htaccess rule was:

RewriteEngine on

RewriteBase /

RewriteCond %{HTTP_HOST} ^(开发者_JAVA技巧www.)?parkeddomain.com$ 
RewriteRule ^(.*)$ /park/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

But for a strange reason, the [L] clause of the park RewriteRule generate an internal 500 error, and I don't have access to the log file :(

Any solution ? thanks :)


You have 500 error most likely because your rule enters into a rewrite loop. Try this rule instead:

RewriteCond %{HTTP_HOST} ^(www.)?parkeddomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.maindomain.com/park/$1 [R=302,L]
  1. It is 302 temporal redirect (because your domain is parked and one day you may decide to actually start using it). But if you really want to can make it 301 Permanent redirect

  2. The rule will work if user come via parkeddomain.com (e.g. http://www.parkeddomain.com/hello).

If you do not want redirect (so URL in a browser still shows http://www.parkeddomain.com/hello instead of http://www.maindomain.com/park/hello), use this instead:

RewriteCond %{HTTP_HOST} ^(www.)?parkeddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/park/
RewriteRule ^(.*)$ /park/$1 [L]

UPDATE This rule will allow to rewrite even this kind of URLs: parkeddomain.com/park/index.php -> /park/park/index.php

RewriteCond %{HTTP_HOST} ^(www.)?parkeddomain\.com$ [NC]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{DOCUMENT_ROOT}/park/$1 -f
RewriteRule ^(.*)$ /park/$1 [L]

PLEASE NOTE: Because it uses %{ENV:REDIRECT_STATUS} it may not work on your hosting (this is used to detect rewrite loop so the rule is only rewritten once).

0

精彩评论

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

关注公众号