Reverse Proxy, rewriting

Tried with $/tixati as well and did not work. I removed path just to test it out and same issue.
Just to be sure I created new slate file and just imported this domain and same thing is happening.

My caddy version and plugins are compiled from today.
Will submit issue at github.

EDIT: If some time comes up could you see if you could replicate the same issue with path so it something not on my end only? @Whitestrake

Yeah, I’ll give it a look later on, will post results in thread.

I’m late to the conversation, but I think you probably want your proxy request without “transparent”. Not certain, but this then means the original request headers are not sent over and your proxy host and path will be used. But the without directive will strip off tixati in this case. So this fixes links in requests.

I would also recommend you change your search pattern to use href="/([^"]+)" and replacement with href="/tixati/{1}". This would then only replace links. And this would fix links in responses.

1 Like

Nice regex. I didn’t think of using a substitution in the replacement.

Does Tixati have any JS loaded by script tag via src? Might need a slight adjustment if so.

It seems to only use

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.2/css/materialize.min.css">

But I have disabled the rule for now as it works on my whole root and not only /tixati.

I have some code here when I go to /tixati/ it sends me to /tixati/home but it seems I have to use two rewrite rules to catch both /tixati/ and tixati/

	redir 307 {
		/tixati     /tixati/home
		/tixati/     /tixati/home
	}

How would I consolidate them into one? I just want it to catch those specific redirects and not everything under /tixati/* .

Firstly, I have to draw a distinction between a rewrite and a redirection. The two operations are very different when it comes to Caddy, handled by different code, and specified as different directives in the Caddyfile.

One such distinguishing detail is that redirects must match the request path exactly (except for / on its own, which catches all requests). That includes trailing slashes. Rewrites, on the other hand, catch everything that matches the basepath.

All that aside, your redir implementation is probably going to be the most efficient way to go. You’ve only got one request (and the trailing slash version of) to worry about, the other option (to rewrite trailing slashes away) will end up with a more verbose Caddyfile anyway.

I see as the currrent code allows me to do
/tixati/
and
/tixati
I guess I will keep them seperated as that did seem the easiest way. I have not grasped rewrite yet but will read up more about it!

A quick comparison of the two;

A redir is external - whenever a client requests /foo, Caddy responds with “No, it’s actually at /bar,” and the conversation ends there.

The client might come back very shortly with a new request for /bar, but that’s up to them (browsers do this by default). The browser’s URL bar will update with the corrected address, and Caddy handles the new request separately from the original.

A rewrite is internal - Caddy sees the request for /foo and just gives the client /bar instead. The client/browser only requests (and gets a response for) /foo.

https://caddyserver.com/docs/rewrite
https://caddyserver.com/docs/redir

1 Like

This was caused by the fact that before v0.8 path and content_type are or combined (and NOT and). I changed this behavior in the current version which should now be available over caddyserver.com for download. You can now change the combination using path_content_type_combination parameter (possible values and/or - default now: and).

See caddy-filter/README.md at master · echocat/caddy-filter · GitHub for more information.

1 Like
	filter rule {
		path $/tixati
		content_type text/html
		#search_pattern href="/([^"]+)"
		#replacement href="/tixati/{1}"
		search_pattern ="/
		replacement ="/tixati/
	}

I tried both these options, i tried swapping the commented against the uncommented but it does not replace the path for some weird reason. I also tried to remove $ from /tixati. So I am not sure this code ever worked as the other glitch just replaced everything.

	proxy /tixati 192.168.1.4:6042 {
		without /tixati
		transparent
	}
	redir 307 {
		/tixati     /tixati/home
		/tixati/     /tixati/home
	}

This is with latest caddy with the bugfix included.

Seems issue is it does not replace anything afterwards like /transfers /home and other which it should do. How would I go on about adding that to regex.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.