0

Seems so simple, proves to be tough to find ... In my .htaccess file I want to create following rewriteRule:

RewriteRule (.*)$  %{HTTP_HOST} + /home.html

Can someone pls tell me how to concatenate a .htaccess variable (HTTP_HOST) and a string (/home.html)

And NO, I cannot redirect to /home.html directly because this .htaccess file serves 2 different domains which are both each located in a subdirectory in my webspace. Apparently the .htaccess file doesn't work when put into a subdirectory .

0

2 Answers 2

1

There is no need for a special “concatenation operator” or something – you just place the variable reference into the substitution, it will get parsed in there automatically.

What you should keep in mind though, is that %{HTTP_HOST} will contain only the host name, no protocol – so it might be necessary to prefix it with a protocol so that it is not treated as a directory.

RewriteRule .* http://%{HTTP_HOST}/home.html [R]

should work. (I added the [R] flag for an explicit redirect [which I guess you want?], because otherwise it might be just an internal one if the host matches the current one.)

Sign up to request clarification or add additional context in comments.

1 Comment

@ CBroe: Spot on! I had tried your concatination solution before, but without the protocoll prefix :( Now the htaccess does the job! Thnx, Arthur
0

Do you mean you want to redirect and NOT TO REWRITE the specific domain into /home.html? Just simply use a rewrite condition:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} domain1\.com$
RewriteRule ^/?$ /home.html [R]

And please explain your question briefly, so I could edit the code to the right one.

2 Comments

@ Servant: Nope, I really need a rewriteRule because of the configuration of the double domain (see initial question)
This is possible, RewriteRule (.*)$ http://%{HTTP_HOST}/home.html and now what do you want?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.