开发者

Getting error 500 when adding RewriteCond with .to domain

开发者 https://www.devze.com 2023-04-01 02:20 出处:网络
I am trying to redirect traffic coming from a specific domain inside my .htaccess file. It works fine unless I do this for a domain with a .to extension. Any idea what is going on here?

I am trying to redirect traffic coming from a specific domain inside my .htaccess file. It works fine unless I do this for a domain with a .to extension. Any idea what is going on here?

Produces error 500:

RewriteCond %{HTTP_HOST}            ^(www\.)?domain\.to [NC]
RewriteRule ^.*$                    /foo/bar [L]

Works fine:

RewriteCond %{HTTP_HOST}            ^(www\.)?domain\.com [NC]
RewriteRule ^.*$                    /foo/bar [L]
开发者_开发技巧


Since I do not know for sure which rule does produce rewrite loop, I can only suggest this approach at this moment:

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.to [NC]
RewriteCond %{REQUEST_URI} !^/foo/bar
RewriteRule ^.*$ /foo/bar [L]

Your attempt is not technically correct for 2 reasons:

  • in .htaccess URL will be without leading slash (I'm referring to $1);
  • you are using $1 .. but you have no matching group setup (in other words $1 will always be empty).

If still nothing -- please provide real htaccess ... or try enabling rewrite debugging (RewriteLogLevel 9) -- but for this you have to have full control over Apache server, as this directive cannot be placed in .htaccess (only server config / virtual host context) + you will need to restart Apache to re-read configuration file.


Try adding this rule somewhere on the top -- where it will be appropriate:

# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
0

精彩评论

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

关注公众号