I'm building my first CouchApp (a simple blogging engine) in order to learn more about it. Now, I have it working to the point that the following URL returns blog posts:
http://127.0.0.1:5984/couchblog/_design/couchblog/_list/index/posts
I have a view called posts that returns my posts, and a list called index that renders the posts. So I figured my next step was to rewrite the URLs to something a bit friendlier. Unfortunately the documentation on URL rewriting seems a tad vague, and I just can't seem to get anything to work.
The rewrite section of my design document looks like this:
rewrites: [{
from: '../../../',
to: '/_list/index/posts',
method: 'GET',
query: ''
}],
I'd like to rewrite it so that it serves the list of blog posts from the web server root, but I just can't seem to get anywhere with it. Can anyone see what I'm doing wrong? I'm using CouchDB 1.6.0 on OS X Snow Leopard via Homebrew.
I'd like to rewrite it so that it serves the list of blog posts from the web server root
I think you need to configure your vhosts settings in the couchdb config for that. This is covered pretty well in the vhosts section so I will just post the relevant part here:-
To add a virtual host, add a CNAME pointer to the DNS for your domain name. For development and testing, it is sufficient to add an entry in the hosts file, typically /etc/hosts` on Unix-like operating systems:
# CouchDB vhost definitions, refer to local.ini for further details
127.0.0.1 couchdb.local
Test that this is working:
$ ping couchdb.local
PING couchdb.local (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_req=1 ttl=64 time=0.025 ms
64 bytes from localhost (127.0.0.1): icmp_req=2 ttl=64 time=0.051 ms
Finally, add an entry to your configuration file in the [vhosts]* section:
[vhosts]
couchdb.local:5984 = /example
*.couchdb.local:5984 = /example
If your CouchDB is listening on the the default HTTP port (80), or is sitting behind a proxy, then you don’t need to specify a port number in the vhost key.
*By the way you can do this from futon as well. Just make sure to restart couchdb after you have configured your vhosts section. Other wise changes will have no effect.
For our case however we need to map the vhosts section to the rewrite handler on our database. So our vhosts will look something like this:-
couchdb.local:5984 = your-db/_design/your-design/_rewrite
Modify your rewirtes handler as well
rewrites: [{
from: 'index',
to: '/_list/index/posts',
method: 'GET',
query: ''
}]
Now if you issue a request to
couchdb.local:5984/index
You should see a list of posts.
Related
I have a server in Azure running two web apps, one on port 443 (IIS), another on 1024 (Apache). Both are https. I have an Azure Application Gateway (WAF v2) in place. I would like to allow requests for subdomain1.domain.com to go through on 443 (which is set-up and working) and requests for subdomain2.domain.com to be re-written to port 1024 internally.
I have tried various combinations of conditions and actions, but cannot get anything to do anything at all, good bad or indifferent!
My current Condition is as follows
Type of variable to check: HTTP Header
Header type: Response Header
Header name: Common Header
Common header: Location
Case-sensitive: No
Operator: =
Pattern to match: (https?):\/\/.*subdomain2.domain.com(.*)$
My current action is:
Re-write type: Response Header
Action type: Set
Header name: Common header
Common header: Location
Header value: https://backendservername.domain.com:1024{http_resp_Location_2}
I can't find a combination that does anything at all, nor any examples that show port updates. I've tried using request headers and the host value, but unfortunately that conflicts with the host rewrite in the HTTP Settings that was necessary to get any end to end SSL working.
Thanks in advance.
Matt.
i have 2 projects running on different ports
localhost:7240
localhost:6040
I would like to have two custom domains like
website.dev -> that points to localhost:7240
admin.dev -> that points to localhost:6040
My host file
127.0.0.1 website.dev
127.0.0.1 admin.dev
and on browser i tryed those
http://website.dev/
http://website.dev:7240/
but none of them worked :/
but if i write
localhost:7240
localhost:6040
will work.
I apprecite any help. Thanks.
OMG !!
I make it work. Follow those rules.
dont user .dev, use something like .local
127.0.0.1 website.local
On chrome disable the https SSL enforcer
chrome://net-internals/#hsts, add the website.local in the Delete domain security policies1
Clear cache or history data
Vistin http://website.local:7240/ Dont forget the / at the end.
I know there have been very similar questions asked but both companies changed over time and it's been hard to get a full working solution.
I'd like to have a naked subdomain (mysite.io) but if I have to have www.mysite.io, that's fine too.
So on the heroku dashboard I have :
DOMAIN NAME : mysite.io DNS TARGET : mysite.io.herokudns.com
DOMAIN NAME : www.mysite.io DNS TARGET www.mysite.io.herokudns.com
I know I should probably only have one of those active but I'm not sure which...
Then, on the NameCheap dashboard, I have :
EDIT: I have read what seemed like a good answer, here's what I changed, awaiting to see if it's gonna work.
CNAME Record - www - www.mysite.io.herokudns.com
CNAME Record - # - mysite.io.herokudns.com
And no redirect
I will update if it works
UPDATE :
Using two CNAME records indeed worked fine, except that users can still connect in HTTP and not be redirected to HTTPS. I probably need to add a redirect for that.
If anyone is still having problems and your website opens without HTTPS. There is a line of code in rails applications which you should uncomment. Go to config/environments/production.rb In this file you will find a commented line "config.force_ssl = true". Uncomment this line and your application will always open up with https
Combination of two answers above will solve the problem for Rails applications:
Go to Namecheap and add the two following CNAME's:
Type: CNAME
Host: #
Value: www.yourdomain.com.herokudns.com
TTL: Automatic
Type: CNAME
Host: www
Value: www.yourdomain.com.herokudns.com
TTL: Automatic
And then follow second answer: "Go to config/environments/production.rb In this file you will find a commented line "config.force_ssl = true"."
That should do the trick.
I have tried to edit my HOSTS file to block just a specific url like so:
127.0.0.1 google.com/pagetoblock
127.0.0.1 www.google.com/pagetoblock
However that isn't working.
Does anyone know where I'm going wrong?
Your HOSTS file only allows you to set the IP address for (as the name suggests) the host (e.g. google.com or www.google.com). You cannot set the IP address for specific pages.
You could use a tool like Microsoft Fiddler to set the IP Address for specific URLs, but this would require Fiddler be running continuously.
Fiddler has a rules engine accessed by Rules → Customize Rules.
There is a great set of samples for your learning, but the following script should work.
For example, to block the logo on the http://www.google.co.uk homepage, you could use the following script:
if (oSession.url == "www.google.co.uk/images/srpr/logo3w.png"){
// Prevent this request from going through an upstream proxy
oSession.bypassGateway = true;
// Rewrite the IP address of target server
oSession["x-overrideHost"] = "127.0.0.1";
// Set the color of the request in RED in Fiddler, for easy tracing
oSession["ui-color"]="red";
}
I need to redirect anyone with a mobile user agent to a file called mobile.php.
My web hosting provider, Net Registry uses the Zeus web server.
Here's the script I've written from my research
RULE_1_START:
# get the document root
map path into SCRATCH:DOCROOT from /
match IN:User-Agent into $ with iPad|iPod|iPhone|Android|s+Mobile
if matched then
set OUT:Location = /mobile.php
endif
RULE_1_END:
I used the instructions on my host's site.
I pasted that into their console and it has worked to do redirects. Net registry have some odd console thing that you submit and it takes 10 minutes to update the zeus server config (annoying as hell).
Anyway my issue is that it redirects me to the wrong location:
So if you visit the site, with a user agent string that contains ipad|ipod|android|\s+mobile then you will trigger it ()
It takes me here:
http://example.com.au/mobile.php,%20catalog/index.php
I can't work out how to fix that, or why that happens because at the moment this file exists:
http://example.com.au/mobile.php
as does this one:
http://example.com.au/index.php. Contents of this file are:
<?php header("Location: catalog/index.php");
Any ideas on how I can make this work more like an apache .htaccess url Rewrite?
the official Zeus documentation
Fixed it by changing
set OUT:Location = /mobile.php
to
set URL = /mobile.php
From the manual...
Using Request Rewrite Scripts
To use the request rewriting functionality, create a script in the Zeus Request
Rewrite Scripting Language. The script contains instructions telling the
Virtual Server how to change the URL or headers of requests that match specified criteria.
The Virtual Server compiles the script, and (if the rewrite functionality is
enabled) uses it every time it receives a request. It runs the commands in the
script, changing the URL if it matches the specified criteria. Once the script is
finished, the Virtual Server continues processing the resulting URL.Zeus Web Server 4.3 User Guide
142 Configuring URL Handling
When changing the URL, the rewrite functionality can only change the local
part of it, that is, the part of the URL after the host name. For example, if a
user requests http://www.myhost.com/sales/uk.html, the rewrite
functionality can only make changes to /sales/uk.html. This means that
you cannot use the rewrite functionality to change the request to refer to a
file on another Virtual Server.
For example, the following script illustrates how to change requests for any
HTML files in the /sales directory so that the user receives them from the
/newsales directory instead:
match URL into $ with ^/sales/(.).html
if matched set URL=/newsales/$1.html
The rewrite functionality can also change the HTTP headers that were received
with a request, and create new HTTP headers to be returned to the user. For
example, the following script changes the HTTP host header, so that a request
for www.mysite.com/subserver is redirected to the Subserver
www.subserver.mysite.com:
match URL into $ with ^/([^/]+)/(.)$
if matched then
set IN:Host = www.$1.mysite.com
set URL = /$2
endif