1

I want to write a rule where I don't know the exact http_host.

For example I have (www.)?example.com. Now I need example to build the following:

(www.)?example.com/example/... in a RewriteRule.

So how can I split the http_host into name only?

1

If you need to get just the domain name, less the TLD. Then you can do something like the following:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?([a-z-]+)\.com [NC]
RewriteRule ^$ /%1/ [R,L]

Where %1 is just the domain name. eg. example in your example.

This assumes a TLD of .com.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.