htaccess rewrite rule with hyphen in tld

340 Views Asked by At

I am trying to write htaccess file that would convert

http://subdomain.my-tld.com/

to

http://my-tld.com/file.php?var=subdomain

Notice the hyphen in the tld.

Here's the htaccess I am using:

Options +FollowSymLinks 
Options -Indexes

RewriteEngine On 

# Rewrite sub domains. 
RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
RewriteCond %{HTTP_HOST} !^www\.my-tld\.com$ [NC] 
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.my-tld\.com$ [NC]
RewriteRule ^(.*)$ /file.php?var=%2 [QSA,L]

I am using the very same code for another domain in the very same server and it is working great, but it is not for this domain. I am guessing that the problem is with the hyphen in this domain.

Any suggestions?

1

There are 1 best solutions below

0
On

For me, these rules make the server return "Internal Server Error", and the error log will print

Request exceeded the limit of 10 internal redirects due to probable configuration error

I'm not sure why it works for another domain as you said, but just try adding this condition before the final RewriteRule:

RewriteCond %{QUERY_STRING} !var=

Make it pass the url alreay get param "var".