is it possible to redirect the user, based on the HTTP-Header content-type
?
For example:
1)
An Application is trying to load localhost/res/123/var/abc
and the content-type
is set to:
application/json
The server should just return the JSON-Result to the application (which is implemented).
2)
If a normal web-browser is visiting the url localhost/res/123/var/abc
, the content-type
is set to:
text/html
In this case the server should redirect the browser to output a webview (e.g. index_web.html
).
Can i realize something like this without using PHP?
The content type is not set at request time, so far as I am aware. Thus, you would need to check if the browser is sending an Accept
header, which describes to the server what kinds of data it will accept (and display) without downloading it. Most browsers do this. They send the following header string to the server (this is obtained from Chrome):
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Therefore, you would need to check the Accept
header using a condition:
RewriteCond %{HTTP:Accept} text/html [NC]
# Then, add your RewriteRules here ...
This will check to see if text/html
is contained in the Accept
header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With