views:

96

answers:

3

I'm not entirely sure if this is possible and tried searching but couldn't find the exact answer to my current situation.

I'm building a service which should allow users to point their own domain to the service. (they need to point an A record towards my server ip)

I'm able to catch the domain using the catch all in apache. So I made a Vhost record for this catch all in httpd.conf. So all not-defined hostnames in apache are pointed towards a certain directory.

Now I would like to pass this domain as a parameter to my service. So is it possible to point this.randomdomain.com to www.mywebserviceurl.com/domain/catch/this.randomdomain.com with .htaccess

The address bar should keep the url this.randomdomain.com

Edit:

RewriteEngine On
RewriteRule ^(.*)$ http://example.com/blogs/string/$1 [R=301]

The above is redirecting but firefox trows an error "The page isn't redirecting properly - Firefox has detected that the server is redirecting the request for this address in a way that will never complete." And the address is changing which I don't want.

thanks!

A: 

See here: http://www.addedbytes.com/apache/mod_rewrite-cheat-sheet/

The directive %{HTTP_REFERER} should do what you're after.

bakkelun
+1  A: 

Exclude that domain from the rule:

RewriteCond %{HTTP_HOST} !=example.com
RewriteRule ^(.*)$ http://example.com/blogs/string/$1 [R=301]

And if you want the domain too:

RewriteCond %{HTTP_HOST} !=example.com
RewriteRule ^(.*)$ http://example.com/blogs/string/%{HTTP_HOST}/$1 [R=301]
Gumbo
thanks, this is working, but how can I make this invisible for the user?
SePP
You will probably use a proxy (requires mod_proxy) to do that. Just add the `P` flag.
Gumbo
if I change [R=301] to [P] it breaks the redirect and I'll get a 404 page not found.
SePP
I probably don't have mod_proxy enabled, will check that.
SePP
enabled mod_proxy and it is working, thanks alot Gumbo.
SePP
A: 

If you use Gumbo's answer, but change the arguments in the braces, you can silently redirect. Change [R=301] to [L], which means it's the last rule that will be executed.

RewriteCond %{HTTP_HOST} !=example.com
RewriteRule ^(.*)$ http://example.com/blogs/string/$1 [L,P]

Edit: After seeing Gumbo's answer, you'll also need mod_proxy enabled and add the P flag.

S Pangborn
I've changed it to [L] the redirect keeps working but he isn't doing it silently. It changes the address bar.
SePP
Gumbo's updated answer should work. I've edited my response to match his.
S Pangborn