kbrmedia / Premium-URL-Shortener

Plugin and modification done to Premium URL Shortener
https://gempixel.com/products/url-shortener-script
50 stars 68 forks source link

Nginx compatibility and script for simpler .htaccess (WP style) #39

Closed renatofrota closed 2 years ago

renatofrota commented 3 years ago

For those struggling on how to make it work with Nginx instead Apache, use a regular Nginx template that forces /index.php for any unrecognized URL, e.g.: the default for WordPress installs on most webhosts:

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

and add to the top of index.php file (after PHP opening tag):

$_GET["a"] = $_GET["a"] ?? ltrim(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH), "/");
if (preg_match('/^admin(\/.*)?/', $_GET["a"])) {
    $_GET["a"] = preg_replace("/^admin\/?/", "", $_GET["a"]);
    require_once("admin/index.php");
    exit;
} elseif ($_GET["a"] == "sitemap.xml") {
    require_once("sitemap.php");
    exit;
}

For script author: you could add this to the next version. This code works for Apache as well, for both the currently provided .htaccess and a more "standard" .htaccess which forces /index.php like the WordPress' default.

kbrmedia commented 2 years ago

Hello

This has been much improved in v6.