Refactor URLs
This commit is contained in:
parent
f9be136345
commit
1e935123c1
6 changed files with 23 additions and 20 deletions
15
.htaccess
15
.htaccess
|
@ -4,14 +4,17 @@
|
|||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
|
||||
# Wishlists / Wish
|
||||
RewriteRule ^([a-z\-]+)/(\d+)$ /?page=$1&id=$2 [QSA,L]
|
||||
|
||||
# Wishlist
|
||||
RewriteRule ^wishlist/([a-z0-9]+)$ /?wishlist=$1 [QSA,L]
|
||||
|
||||
# Page
|
||||
RewriteRule ^([a-z\-]+)$ /?page=$1 [QSA,L]
|
||||
|
||||
# Wishlists (My lists)
|
||||
RewriteRule ^(wishlists)/([0-9]+)$ /?page=$1&id=$2 [QSA,L]
|
||||
|
||||
# Wish
|
||||
RewriteRule ^(wish)/(\d+)$ /?page=$1&id=$2 [QSA,L]
|
||||
|
||||
# Wishlist
|
||||
RewriteRule ^(wishlist)/([0-9a-f]{40})$ /?page=$1&hash=$2 [QSA,L]
|
||||
</IfModule>
|
||||
|
||||
##-- When caching of gzipped JS and CSS files is used, enable this setting
|
||||
|
|
|
@ -148,13 +148,6 @@ if ($options && $options->getOption('isInstalled') && !(defined('ENV_IS_DEV') &&
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wishlist
|
||||
*/
|
||||
if (!isset($_SESSION['_GET']['page']) && isset($_SESSION['_GET']['wishlist'])) {
|
||||
$page = 'wishlist';
|
||||
}
|
||||
|
||||
/**
|
||||
* Page
|
||||
*/
|
||||
|
|
|
@ -49,7 +49,7 @@ $(function () {
|
|||
if (wishlistValue) {
|
||||
wishlist.id = wishlistValue;
|
||||
|
||||
$('.wishlist-share').attr('href', '/?wishlist=' + wishlists[wishlistIndex].hash);
|
||||
$('.wishlist-share').attr('href', '/?page=wishlist&hash=' + wishlists[wishlistIndex].hash);
|
||||
|
||||
$('.button.wishlist-wish-add').removeClass('disabled');
|
||||
$('.button.wishlist-share').removeClass('disabled');
|
||||
|
@ -65,7 +65,7 @@ $(function () {
|
|||
.then(handleFetchError)
|
||||
.then(handleFetchResponse)
|
||||
.then(function(response) {
|
||||
window.history.pushState({}, '', response.data.url);
|
||||
window.history.replaceState(null, document.title, response.data.url);
|
||||
|
||||
$('.ui.dropdown.filter.priority')
|
||||
.dropdown('restore default value')
|
||||
|
|
|
@ -164,7 +164,7 @@ class Page
|
|||
if ($options && $options->getOption('isInstalled') && isset($_SESSION['_GET'])) {
|
||||
$url = new URL(http_build_query($_SESSION['_GET']));
|
||||
|
||||
if ($url->isPretty()) {
|
||||
if (false === $url->isPretty()) {
|
||||
redirect($url->getPretty());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,18 @@ namespace wishthis;
|
|||
|
||||
class URL
|
||||
{
|
||||
public function __construct(private string $url)
|
||||
public string $url;
|
||||
|
||||
public function __construct(string $url)
|
||||
{
|
||||
$this->url = urldecode($url);
|
||||
}
|
||||
|
||||
public function isPretty(): bool
|
||||
{
|
||||
return preg_match('/^\/\?.+?=.+?$/', $this->url);
|
||||
$isPretty = 1 === preg_match('/^\/[a-z0-9\/]+/', $this->url);
|
||||
|
||||
return $isPretty;
|
||||
}
|
||||
|
||||
public function getPermalink(): string
|
||||
|
@ -95,6 +100,8 @@ class URL
|
|||
) {
|
||||
$rewriteRule = str_replace($match, $value, $rewriteRule);
|
||||
|
||||
error_log('Successfully matched ' . $match . ' with ' . $value . ' New rule is now: ' . $rewriteRule);
|
||||
|
||||
$countMatches++;
|
||||
break;
|
||||
}
|
||||
|
@ -114,6 +121,6 @@ class URL
|
|||
}
|
||||
}
|
||||
|
||||
return $pretty_url ?: '?' . $this->url;
|
||||
return $pretty_url ?: '/?' . $this->url;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace wishthis;
|
||||
|
||||
$wishlist = new Wishlist($_SESSION['_GET']['wishlist']);
|
||||
$wishlist = new Wishlist($_SESSION['_GET']['hash']);
|
||||
$page = new Page(__FILE__, $wishlist->getTitle());
|
||||
|
||||
if (!$wishlist->exists) {
|
||||
|
|
Loading…
Reference in a new issue