I have an hash configuration like this
sub vcl_init {
new bar = directors.hash();
bar.add_backend(server1, 1.0);
bar.add_backend(server2, 1.0);
}
I would like to add a rewrite rule that if in the url there is a word it must redirect to one specific internal server
if (req.url ~ "/newsletter" ) {
set req.http.x-redir = "https://" + "10.1.3.4" + req.url;
return (synth (301, req.http.x-redir));
}
But this rule doesn't work because 10.1.3.4 is an internal ip not a DNS. Is it possible to do this?
Seems like you want to use a different director backend (the internal server) if the request contains newsletter. Thats possible.
Example
sub vcl_recv {
if (req.url ~ "^/newsletter") {
set req.backend = newsletter;
} else {
set req.backend = default.
}
}
See https://varnish-cache.org/docs/3.0/tutorial/advanced_backend_servers.html
But you cant do a 301, thats for the external request, while here we are talking internal routing.
Related
I haaave been trying to set up a cloudflare worker to redirecet an URL to another (SOURCE.ie/... -> DESTINATION.com/...).
The destination URL is set up within cloudflare the source-URL however is purchased via Onlydomains.
I have been using the code given in the documentation:
const base = "https://DESTINATION.com"
const statusCode = 301
async function handleRequest(request) {
const url = new URL(request.url)
const { pathname, search } = url
const destinationURL = base + pathname + search
return Response.redirect(destinationURL, statusCode)
}
addEventListener("fetch", async event => {
event.respondWith(handleRequest(event.request))
})
What I think have to do now is to aadd a route but is does not want to do that:
Although I added the nameservers to the Onlydomains URL.
Am I missing something? I just want a simple redirect that replaces SOURCE with DESTINATION :|
I have a Vapor app that needs to do most things authenticated via HTTPS, but also needs to receive unauthenticated PUT requests via HTTP.
Can I conditionalize my route definitions based on the server's host name or authentication type? How can I capture that information from the server?
If you start up the different instances of vapor using the command line argument --hostname, you can put this code in your configure.swift and then include different routes as needed per host. You will then get 404s if invalid routes are attempted on the wrong hosts.
if let index = env.arguments.index(of: "--hostname")
{
if env.arguments.count > index
{
let hostname = env.arguments[index+1]
if hostname == "hostA"
{
// load routes
}
else
{
// load other routes
}
}
}
An alternative is to use custom Middleware. Something like this enables the hostname being called in the request to be inspected and prohibited routes can be re-directed:
struct HostSpecificMiddleware:Middleware
{
func respond( to request: Request, chainingTo next: Responder ) throws -> Future<Response>
{
let host = request.http.headers.filter{ (arg) in let (name, _) = arg; return name == "Host" }[0]
if host.1 == "hostA:8080"
{
if request.http.url.path == "routeA"
{
throw Abort.redirect(to:"routeNotAllowed")
}
}
return try next.respond(to: request)
}
}
You can then configure the middleware into routes in configure.swift using:
let soMW = HostSpecificMiddleware()
let users = router.grouped(uriUsers).grouped(soMW)
The second approach gives you much more flexibility.
I am new to Grails and I am working on an exisiting application. I am trying to force the anyone using our website to allways be on https. I added the Spring Security Core plugin
//BuildConfig.groovy
compile "org.grails.plugins:spring-security-core:2.0.0"
and I just added
///Config.groovy
grails.plugin.springsecurity.secureChannel.definition = [
'/**': 'REQUIRES_SECURE_CHANNEL'
When I try to go on localhost:8080/myapp, it redirects me to https://localhost:8443/myapp, but I get a "This webpage has a redirect loop ERR_TOO_MANY_REDIRECTS" message.
I added print statements in my SecurityFilters.groovy, and I can see the infinite loop going
baseFilter(controller: "*", action: "*")
{
before = {
println "baseFilter"
// If auth controller then ok to continue
if (controllerName.equals("auth"))
{
return true;
}
// If no subject (user) and not auth controller then user must authenticate
if (!session.subject && !(controllerName.equals("auth")))
{
params.targetUri = request.forwardURI - request.contextPath
if (params.action=="profile") {
params.targetUri=params.targetUri + "?page=" + params?.page
}
else if (params.action=="results") {
params.targetUri="/home"
}
println "baseFilter: Redirecting: PARAMS = $params"
redirect(controller:'auth', action:'login', params: params)
return false;
}
}
}
It's just:
baseFilter
baseFilter: Redirecting: PARAMS = [action:auth, format:null, controller:login, targetUri:/login/auth]
Over and over.
I've tried many other things I found on Stackoverflow and other websites, but they either do not work, or are too complicated.
Thank you.
Ok, so this isn't the answer to the question, but I managed to achieve what I was trying to do, which was to force SLL, and redirect any attempts to use http. I did this by using the shiro plugin, which was already being used by my application. In the Buildconfig.groovy, just add compile ":shiro:1.2.1" to you plugins. In the config.groovy I added the following properties:
security {
shiro {
filter {
loginUrl = "/login"
successUrl = "/"
unauthorizedUrl = "/unauthorized"
filterChainDefinitions = """
/** = ssl[443]
"""
}
}
}
You can modify your filterChainDefinitions to only force ssl on certain urls. I just used /** because I always want SSL.
I Use StimulSoft Ver:2015.2 in my MVC Web Application
I Use This Code In My View :
#Html.Stimulsoft().RenderMvcViewerScripts();
<div>
#Html.Stimulsoft().StiMvcViewerFx(options: new StiMvcViewerFxOptions
{
Theme = StiThemeFx.Office2013,
Actions =
{
GetReportSnapshot = "GetReportSnapshotForPeriodic",
// ViewerEvent = "ViewerEvent",
//Interaction = "Interaction",
//DesignReport = "GetReportTemplate"
},
Appearance =
{
},
Toolbar =
{
ShowParametersButton = true
}
})
</div>
When I run the application it works correct in LocalNetwork but when I use microtech to redirect my Valid Ip To My Local and I run the web site from valid ip it gots error of:
Failed to load resource: the server responded with a status of 404 (Not Found)
Infact GetReportSnapshot = "GetReportSnapshotForPeriodic",not find on server with port 8818 or any other port
how can I redirect to Getreportsnapshot with same ip and port?
Which file should I insert this code?
You should use the UseRelativeUrls option if you change the server.
#Html.Stimulsoft().StiMvcViewerFx(options: new StiMvcViewerFxOptions
{
Server =
{
UseRelativeUrls = true
}
I would like to redirect urls that are using the wrong url alias.
Example, in my site I have:
English -> /prices/high-school -> node/112
Spanish -> (/es)/precios/high-school -> node/115
When a person or search engine reaches /es/prices/high-school a 404 is returned. What I would like is to redirect /es/prices/high-school to node/115.
I would like to do this in a general form, writing a module or using an existing one if possbile.
Thanks.
I already figured it out.
In the preprocess hook I need to check the page, strip the prefix and get the node id from the original id.
See code below:
if(current_path()=="search404")
{
$url = request_path();
if (startsWith($url,'es/') ||
startsWith($url,'de/') ||
startsWith($url,'it/') ||
startsWith($url,'fr/') )
{
$originalPath = substr($url,3,strlen($url)-3);
$path = drupal_lookup_path("source", $originalPath,"en");
if (isset($path))
{
$node = menu_get_object("node", 1, $path);
if (isset($node))
{
$prefix = substr($url,0,2);
$translated_paths = translation_path_get_translations('node/' . $node->nid);
if (isset($translated_paths) && array_key_exists ($prefix,$translated_paths))
{
if (isset($_GET['destination'])) {
unset($_GET['destination']);
}
$new_path = $translated_paths[$prefix];
drupal_goto($new_path, array(),301);
}
}
}
}
}
It won't be a solution to add different url aliases for the language versions? I mean:
node/112 -> /prices/high-school
node/115 -> /es/precios/escuela-secundaria
i18n module handles language based paths and redirects too.