Whmcs friendly URL setting will not work with nginx. How can I fix this? - whmcs

I am trying to setup full friendly urls on whmcs, but I can not get the configuration to work. I have tried various configurations but none seems to work, and the ones that do work break other things, such as the admin urls.
https://whmcs.community/topic/291496-moderncurrent-76-nginx-rules/
I have tried this, but it does not work for all URLs

Try these configurations
location ~ /billing/announcements/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/announcements/$1;
}
location ~ /billing/downloads/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/downloads/$1;
}
location ~ /billing/knowledgebase/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/knowledgebase/$1;
}
location ~ /billing/store/ssl-certificates/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/store/ssl-certificates/$1;
}
location ~ /billing/store/sitelock/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/store/sitelock/$1;
}
location ~ /billing/store/website-builder/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/store/website-builder/$1;
}
location ~ /billing/store/order/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/store/order/$1;
}
location ~ /billing/download/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/download$1;
}
location ~ /billing/cart/domain/renew/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/cart/domain/renew$1;
}
location ~ /billing/knowledgebase/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/knowledgebase/$1;
}
location ~ /billing/store/ssl-certificates/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/store/ssl-certificates/$1;
}
location ~ /billing/store/sitelock/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/store/sitelock/$1;
}
location ~ /billing/store/website-builder/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/store/website-builder/$1;
}
location ~ /billing/store/order/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/store/order/$1;
}
location ~ /billing/download/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/download$1;
}
location ~ /billing/admin/setup/authn/view/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/setup/authn/view/$1;
}
location ~ /billing/admin/apps/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/apps$1;
}
location ~ /billing/admin/setup/notifications/overview/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/setup/notifications/overview$1;
}
location ~ /billing/admin/setup/storage/index/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/setup/storage/index$1;
}
location ~ /billing/admin/setup/payments/tax/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/setup/payments/tax$1;
}
location ~ /billing/admin/help/license/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/help/license$1;
}
location ~ /billing/admin/setup/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/setup$1;
}
location ~ /billing/admin/utilities/system/php-compat/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/utilities/system/php-compat$1;
}
location ~ /billing/admin/services/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/services$1;
}
location ~ /billing/admin/services/shared/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/services/shared$1;
}
location ~ /billing/admin/services/reseller/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/services/reseller$1;
}
location ~ /billing/admin/services/server/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/services/server$1;
}
location ~ /billing/admin/services/other/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/services/other$1;
}
location ~ /billing/admin/addons/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/addons$1;
}
location ~ /billing/admin/domains/?(.*)$ {
rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/domains$1;
}
Reference

please what convert to .htaccess?
EX
location ~ /billing/store/sitelock/?(.*)$ {
rewrite ^/(.*)$ /billing/index.php?rp=/store/sitelock/$1;
}

Related

Vite proxy server rewrite

/**
* Generate proxy
* #param list
*/
export function createProxy(list: ProxyList = []) {
const ret: ProxyTargetList = {};
for (const [prefix, target] of list) {
const isHttps = httpsRE.test(target);
// https://github.com/http-party/node-http-proxy#options
ret[prefix] = {
target: target,
changeOrigin: true,
ws: true,
rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
// https is require secure=false
...(isHttps ? { secure: false } : {}),
};
}
console.log('proxy list');
console.log(ret);
return ret;
}
I have above method to create a list of proxy based on different prefix which defined in .env.development.
VITE_PROXY = [["/basic-api","http://127.0.0.1:3100"],["/api","http://127.0.0.1:8080"],["/upload","http://localhost:3300/upload"]]
But when I request url http://127.0.0.1/api/xxx, it is not rewrite to http://127.0.0.1:8080 as expected.
then I just add return path in rewrite function like this:
rewrite: (path) =>
{path.replace(new RegExp(`^${prefix}`), '');return path},
Then it works.
I am confused now. What's the difference there? I googled a lot about vite proxy rewrite, normally, no need to add return statement like I just did.
Thanks!
Hint: rewrite: (path) => {path.replace(new RegExp(^${prefix}), '');return path},
will return you the original, untransformed path, since replace returns a new string. Please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace.
So probably the regex or underlying logic is not correct.

Istio configuration for websites with static content (in particular kubevious UI)

I'm trying to configure istio VirtualService so that I can open the kubevious dashboard (https://github.com/kubevious/kubevious) through it.
I have the following setup:
resource "kubernetes_manifest" "kubevious" {
provider = kubernetes-alpha
manifest = {
apiVersion = "networking.istio.io/v1alpha3"
kind = "VirtualService"
metadata = {
name = "kubevious"
namespace = "kubevious"
}
spec = {
gateways = [
"istio-system/space-gateway"
]
hosts = [
"*"
]
http = [
{
match = [
{
uri = {
prefix = "/kubevious"
}
}
]
rewrite = {
uri = "/"
}
route = [
{
destination = {
host = "kubevious-ui-svc.kubevious.svc.cluster.local"
}
}
]
},
{
match = [
{
uri = {
prefix = "/static"
}
},
{
uri = {
prefix = "/socket"
}
},
{
uri = {
regex: "^.*\\.(ico|png|jpg)$"
}
}
]
route = [
{
destination = {
host = "kubevious-ui-svc.kubevious.svc.cluster.local"
}
}
]
}
]
}
}
}
kubevious website is opening (albeit with some socket errors which I guess are related to kubevious).
I have one issue with this approach. What if I want to host more websites which have static content? Currently everything that goes to %istio_ingress_ip%/static will be forwarded to kubevious. Any other way to configure it so that i.e. when I invoke %istio_ingress_ip%/kubevious, it will resolve the static content to %istio_ingress_ip%/kubevious/static?
What if I want to host more websites which have static content?
AFAIK you should specify hosts for that, instead of *
For example let's say you have 2 static sites, example.com and sample.com, then you create 2 hosts in your virtual service.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: example-vs
spec:
hosts:
- example.com <----
http:
- match:
- uri:
prefix: /example
- uri:
prefix: /static
- uri:
prefix: /socket
- uri:
regex: "^.*\\.(ico|png|jpg)$"
route:
- destination:
host: example.default.svc.cluster.local
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: sample-vs
spec:
hosts:
- sample.com <----
http:
- match:
- uri:
prefix: /sample
- uri:
prefix: /static
- uri:
prefix: /socket
- uri:
regex: "^.*\\.(ico|png|jpg)$"
route:
- destination:
host: sample.default.svc.cluster.local
Additional resources:
https://medium.com/#MATT.LAW/istio-and-the-path-to-production-cdb260d58c85
Any other way to configure it so that i.e. when I invoke %istio_ingress_ip%/kubevious, it will resolve the static content to %istio_ingress_ip%/kubevious/static?
There are few resources worth to check about rewrite in istio.
istio: VirtualService rewrite to the root url
https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRewrite
https://discuss.istio.io/t/rewrite-url-to-the-root-in-the-gateway/2860/3

Nuxt.js - force trailing slash at the end of all urls

I'm looking for a way to make sure that all of my urls end with a trailing slash (so first check if there is already a trailing slash at the end, and if not add one).
I have tried with nuxt-redirect-module, and it works adding the slash but then it leads to an infinite redirect
redirect: [
{
from: '^(.*)$',
to: (from, req) => {
let trailingUrl = req.url.endsWith('/') ? req.url : req.url + '/'
return trailingUrl
}
}
]
Any insight will be welcome. Thanks!
The following regex handles query string as well:
redirect: [
{
from: '^(\\/[^\\?]*[^\\/])(\\?.*)?$',
to: '$1/$2',
},
],
You can try to match only those URLs that do not end with a slash:
redirect: [
{
from: '^.*(?<!\/)$',
to: (from, req) => req.url + '/'
}
]
I had the same problem, but I didn't want to use the redirects. I tried a lot of solutions, but finally it turned out that adding a double slash to the routing path had the desired effect:
router: {
prefetchLinks: false,
middleware: 'navigation',
routeNameSplitter: '/',
extendRoutes(routes, resolve) {
routes.push(
{
name: 'kaufen',
path: '/kaufen//',
component: resolve(__dirname, 'pages/listing/index.vue'),
},
{
name: 'mieten',
path: '/mieten//',
component: resolve(__dirname, 'pages/listing/index.vue'),
},
This results in:
https://example.com/kaufen/?alternate=true&ignoreToplisting=false
It seems very hacky, but it does the trick!

LESS - use nth-child variable in string

Surely there's a way to rewrite the following in LESS?
#bg-slider{
li:nth-child(1){
background:url('../images/bg1.jpg');
}
li:nth-child(2){
background:url('../images/bg2.jpg');
}
li:nth-child(3){
background:url('../images/bg3.jpg');
}
}
I've tried:
.bg-image (#slide) {
background:url('../images/bg#{slide}.jpg');
}
#bg-slider{
li:nth-child(n){
.bg-image(n);
}
}
But that just gives '../images/bgn.jpg' for all li's.
#bg-slider {
li {
.bkg(1);
.bkg(2);
.bkg(3);
}
.bkg(#i) {
&:nth-child(#{i}) {
background: url('../images/bg#{i}.jpg');
}
}
}

Phalconphp micro mvc routing issue

I have just started working on a simple restful service.
The folder structure I have is like so:
root
- /api
--/api/customers.php
So for example in the browser I intend to call http://domain/api/customers/fetchall
However, I only ever get the notFound handler called. The code in customers.php is:
<?php
use Phalcon\DI\FactoryDefault,
Phalcon\Mvc\Micro,
Phalcon\Config\Adapter\Ini;
$di = new FactoryDefault();
$di->set('config', function() {
return new Ini("config.ini");
});
$app = new Micro($di);
/**
* Create new customer
*/
$app->post('/create', function(){});
/**
* Retrieve all customers
*/
$app->get('/fetchall', function() use ($app) {
$data = array();
$data[] = array(
'id' => '123456',
'name' => 'customerName',
);
echo json_encode($data);
});
/**
* Find customer by name
*/
$app->get('/search/{name}', function($name){});
/**
* Find customer by email
*/
$app->get('/search/{email}', function($email){});
/**
* Find customer by postcode
*/
$app->get('/search/{postcode}', function($postcode){});
/**
* Move a customer
*/
$app->put('/move/{oldpostcode}/{newpostcode}', function($oldpostcode, $newpostcode){});
/**
* Delete customer
*/
$app->delete('/delete/{id:[0-9]+}', function($id) use ($app) {
$response = new Phalcon\Http\Response();
$response->setJsonContent(array('status' => 'OK'));
return $response;
});
$app->notFound(function () use ($app) {
$app->response->setStatusCode(404, "Not Found")->sendHeaders();
echo 'This is crazy, but this page was not found!';
});
//echo $_SERVER['REQUEST_URI'];
$app->handle();
If i instead use / instead of /fetchall then in works but it also matches any url as well which is no good.
Appreciate the help in advance.
Thanks
Adam
Look like a bug, but you need to specify the URL you want your application handles:
$app->handle(filter_input(INPUT_SERVER, 'REQUEST_URI'));
Replace REQUEST_URI by what you need.
In case you are still looking for an answer:
If you don't have .htacess please create one and add the following: as per tutorial
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ api/customers.php?_url=/$1 [QSA,L]
</IfModule>
Then in your code you have to edit paths that are to be matched from say:
$app->get('/fetchall', function() use ($app) {
to:
$app->get('/api/customers/fetchall', function() use ($app) {
That's all there was to it.
You guy may forgot to add the /api/customers prefix to your route. Try with this:
$app->get('/api/customers/fetchall', function() use ($app) {
$data = array();
$data[] = array(
'id' => '123456',
'name' => 'customerName',
);
echo json_encode($data);
});