mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Fixed some 404 errors when using Part-DB without URL rewriting.
Fixed problems with the ajaxUI. Also added an ENV option that RedirectController redirects you to index.php/en page version.
This commit is contained in:
parent
2c34c5f9cb
commit
280b2d4427
5 changed files with 45 additions and 3 deletions
4
.env
4
.env
|
@ -39,4 +39,8 @@ MAILER_URL=null://localhost
|
||||||
|
|
||||||
FIXER_API_KEY=CHANGEME
|
FIXER_API_KEY=CHANGEME
|
||||||
|
|
||||||
|
# Change this to true, if no url rewriting (like mod_rewrite for Apache) is available
|
||||||
|
# In that case all URL contains the index.php front controller in URL
|
||||||
|
NO_URL_REWRITE_AVAILABLE=false
|
||||||
|
|
||||||
### End custom vars
|
### End custom vars
|
|
@ -76,7 +76,11 @@ class AjaxUI {
|
||||||
|
|
||||||
console.info("AjaxUI started!");
|
console.info("AjaxUI started!");
|
||||||
|
|
||||||
this.BASE = $("body").data("base-url") + "/";
|
this.BASE = $("body").data("base-url");
|
||||||
|
//If path doesn't end with slash, add it.
|
||||||
|
if(this.BASE[this.BASE.length - 1] !== '/') {
|
||||||
|
this.BASE = this.BASE + '/';
|
||||||
|
}
|
||||||
console.info("Base path is " + this.BASE);
|
console.info("Base path is " + this.BASE);
|
||||||
|
|
||||||
//Show flash messages
|
//Show flash messages
|
||||||
|
|
|
@ -53,6 +53,7 @@ services:
|
||||||
App\Controller\RedirectController:
|
App\Controller\RedirectController:
|
||||||
arguments:
|
arguments:
|
||||||
$default_locale: '%locale%'
|
$default_locale: '%locale%'
|
||||||
|
$enforce_index_php: '%env(bool:NO_URL_REWRITE_AVAILABLE)%'
|
||||||
|
|
||||||
App\Command\UpdateExchangeRatesCommand:
|
App\Command\UpdateExchangeRatesCommand:
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
@ -42,14 +42,22 @@ class RedirectController extends AbstractController
|
||||||
protected $default_locale;
|
protected $default_locale;
|
||||||
protected $translator;
|
protected $translator;
|
||||||
protected $session;
|
protected $session;
|
||||||
|
protected $enforce_index_php;
|
||||||
|
|
||||||
public function __construct(string $default_locale, TranslatorInterface $translator, SessionInterface $session)
|
public function __construct(string $default_locale, TranslatorInterface $translator, SessionInterface $session, bool $enforce_index_php)
|
||||||
{
|
{
|
||||||
$this->default_locale = $default_locale;
|
$this->default_locale = $default_locale;
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
|
$this->enforce_index_php = $enforce_index_php;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is called whenever a route was not matching the localized routes.
|
||||||
|
* The purpose is to redirect the user to the localized version of the page.
|
||||||
|
* @param Request $request
|
||||||
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||||
|
*/
|
||||||
public function addLocalePart(Request $request)
|
public function addLocalePart(Request $request)
|
||||||
{
|
{
|
||||||
//By default we use the global default locale
|
//By default we use the global default locale
|
||||||
|
@ -69,6 +77,31 @@ class RedirectController extends AbstractController
|
||||||
|
|
||||||
//$new_url = str_replace($request->getPathInfo(), '/' . $locale . $request->getPathInfo(), $request->getUri());
|
//$new_url = str_replace($request->getPathInfo(), '/' . $locale . $request->getPathInfo(), $request->getUri());
|
||||||
$new_url = $request->getUriForPath('/' . $locale . $request->getPathInfo());
|
$new_url = $request->getUriForPath('/' . $locale . $request->getPathInfo());
|
||||||
|
|
||||||
|
//If either mod_rewrite is not enabled or the index.php version is enforced, add index.php to the string
|
||||||
|
if (($this->enforce_index_php || !$this->checkIfModRewriteAvailable())
|
||||||
|
&& strpos($new_url, 'index.php') === false) {
|
||||||
|
//Like Request::getUriForPath only with index.php
|
||||||
|
$new_url = $request->getSchemeAndHttpHost(). $request->getBaseUrl().'/index.php/' . $locale . $request->getPathInfo();
|
||||||
|
}
|
||||||
return $this->redirect($new_url);
|
return $this->redirect($new_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if mod_rewrite is availabe (URL rewriting is possible).
|
||||||
|
* If this is true, we can redirect to /en, otherwise we have to redirect to index.php/en.
|
||||||
|
* When the PHP is not used via Apache SAPI, we just assume that URL rewriting is available
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function checkIfModRewriteAvailable()
|
||||||
|
{
|
||||||
|
if (!function_exists('apache_get_modules')) {
|
||||||
|
//If we can not check for apache modules, we just hope for the best and assume url rewriting is available
|
||||||
|
//If you want to enforce index.php versions of the url, you can override this via ENV vars.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if the mod_rewrite module is loaded
|
||||||
|
return in_array('mod_rewrite', apache_get_modules(), false);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -18,7 +18,7 @@
|
||||||
{{ encore_entry_link_tags('app') }}
|
{{ encore_entry_link_tags('app') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body data-base-url="{{ app.request.basePath }}/{{ app.request.locale }}">
|
<body data-base-url="{{ url('homepage', {'_locale': app.request.locale}) }}">
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue