-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchanges.patch
More file actions
519 lines (485 loc) · 18.9 KB
/
changes.patch
File metadata and controls
519 lines (485 loc) · 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
diff --git a/app/Console/Commands/SetupNewTenant.php b/app/Console/Commands/SetupNewTenant.php
index 115449d1..12546d9a 100644
--- a/app/Console/Commands/SetupNewTenant.php
+++ b/app/Console/Commands/SetupNewTenant.php
@@ -316,7 +316,7 @@ private function updateDomainConfig(string $domain): bool
$newDomain = "\n '{$domain}' => [\n";
$newDomain .= " 'name' => '{$appName}',\n";
$newDomain .= " 'type' => 'tenant',\n";
- $newDomain .= " 'index_in_google' => false,\n";
+ $newDomain .= " 'index_in_google' => true,\n";
$newDomain .= " 'features' => ['all'],\n";
$newDomain .= " 'description' => 'Tenant domain',\n";
$newDomain .= " ],\n";
diff --git a/app/Services/SeoService.php b/app/Services/SeoService.php
index 578743b2..96fa4752 100644
--- a/app/Services/SeoService.php
+++ b/app/Services/SeoService.php
@@ -2,6 +2,7 @@
namespace App\Services;
+use App\Support\TenantDomain;
use App\Models\Seo;
use App\Models\WritesCategories\WriteImage;
use Illuminate\Support\Facades\Cache;
@@ -32,7 +33,7 @@ public function getGlobalSeo(): array
// Laravel cache ile DB sorgularını minimize et
self::$cachedData = Cache::remember($this->getCacheKey(), self::CACHE_TTL, function () {
- $domain = $this->normalizeDomain(request()->getHost());
+ $domain = TenantDomain::current();
// Get or create SEO data for current domain
$seo = Seo::firstOrCreate(
@@ -41,8 +42,8 @@ public function getGlobalSeo(): array
'site_name' => config('app.name'),
'title' => config('app.name'),
'description' => 'Site açıklaması',
- 'language' => 'tr',
- 'locale' => 'tr_TR',
+ 'language' => config('app.locale', 'tr'),
+ 'locale' => config('app.locale', 'tr') === 'en' ? 'en_US' : 'tr_TR',
'robots' => 'index, follow',
]
);
@@ -188,7 +189,7 @@ public function getFullMeta(?string $pageTitle = null, ?string $pageDescription
'og' => [
'title' => $pageTitle ?? $global['ogTitle'],
'description' => $pageDescription ?? $global['ogDescription'],
- 'image' => $global['ogImage'],
+ 'image' => $this->toAbsoluteUrl($global['ogImage']),
'type' => 'website',
'locale' => $global['locale'],
'site_name' => $global['siteName'],
@@ -201,12 +202,12 @@ public function getFullMeta(?string $pageTitle = null, ?string $pageDescription
'creator' => $global['twitterCreator'],
'title' => $pageTitle ?? $global['ogTitle'],
'description' => $pageDescription ?? $global['ogDescription'],
- 'image' => $global['ogImage'],
+ 'image' => $this->toAbsoluteUrl($global['ogImage']),
],
// Icons
- 'favicon' => $global['favicon'],
- 'appleTouchIcon' => $global['appleTouchIcon'],
+ 'favicon' => $this->toAbsoluteUrl($global['favicon']),
+ 'appleTouchIcon' => $this->toAbsoluteUrl($global['appleTouchIcon']),
'themeColor' => $global['themeColor'],
// Verification
@@ -233,24 +234,15 @@ public function getFullMeta(?string $pageTitle = null, ?string $pageDescription
*/
private function getCacheKey(): string
{
- $domain = $this->normalizeDomain(request()->getHost());
- return "seo_data_{$domain}";
+ return 'seo_data_' . TenantDomain::current();
}
/**
- * Normalize domain (www. prefix'ini kaldır)
- *
- * @param string $domain
- * @return string
+ * @deprecated Use TenantDomain::normalize()
*/
private function normalizeDomain(string $domain): string
{
- // www. prefix'ini kaldır
- if (str_starts_with($domain, 'www.')) {
- return substr($domain, 4);
- }
-
- return $domain;
+ return TenantDomain::normalize($domain);
}
/**
@@ -498,69 +490,41 @@ public function getHomepageSchema(array $contentSummary = []): array
}
/**
- * Get canonical URL for current page
- *
- * Park edilmiş domainler ana domain'e işaret eder.
- * Bu duplicate content cezasını önler.
- *
- * @param string|null $path Custom path (opsiyonel, default: current path)
- * @return string Full canonical URL
+ * Get canonical URL for current page.
+ * Indexed tenant domains use their own APP_URL; others may point to canonical_target.
*/
public function getCanonicalUrl(?string $path = null): string
{
- $currentDomain = $this->normalizeDomain(request()->getHost());
- $mainDomain = config('domains.main_domain', 'checkupcodes.com');
- $domainConfig = config("domains.domains.{$currentDomain}", []);
-
- // Eğer bu domain Google'da indexlenecekse, kendi URL'ini kullan
- // Değilse (parked domain), ana domain'e yönlendir
- $shouldUseMainDomain = !($domainConfig['index_in_google'] ?? false);
-
- $targetDomain = $shouldUseMainDomain ? $mainDomain : $currentDomain;
-
- // Path belirtilmemişse, mevcut path'i kullan
+ $currentDomain = TenantDomain::current();
+ $domainConfig = TenantDomain::config($currentDomain);
+ $baseUrl = TenantDomain::baseUrl();
+
+ if (!($domainConfig['index_in_google'] ?? false)) {
+ $targetDomain = $domainConfig['canonical_target'] ?? config('domains.main_domain', 'checkupcodes.com');
+ $baseUrl = 'https://' . TenantDomain::normalize($targetDomain);
+ }
+
if ($path === null) {
$path = request()->path();
}
-
- // Path'i temizle
+
$path = ltrim($path, '/');
-
- // Eğer path boşsa (homepage), sadece domain döndür
- if (empty($path) || $path === '/') {
- return "https://{$targetDomain}";
+
+ if ($path === '' || $path === '/') {
+ return $baseUrl;
}
-
- return "https://{$targetDomain}/{$path}";
+
+ return "{$baseUrl}/{$path}";
}
- /**
- * Check if current domain should be indexed by Google
- *
- * @return bool
- */
public function shouldIndexInGoogle(): bool
{
- $currentDomain = $this->normalizeDomain(request()->getHost());
- $domainConfig = config("domains.domains.{$currentDomain}", []);
-
- return $domainConfig['index_in_google'] ?? false;
+ return TenantDomain::shouldIndex(TenantDomain::current());
}
- /**
- * Get domain configuration
- *
- * @return array
- */
public function getDomainConfig(): array
{
- $currentDomain = $this->normalizeDomain(request()->getHost());
- return config("domains.domains.{$currentDomain}", [
- 'name' => config('app.name'),
- 'type' => 'unknown',
- 'index_in_google' => true,
- 'features' => ['all'],
- ]);
+ return TenantDomain::config(TenantDomain::current());
}
/**
@@ -573,18 +537,25 @@ public function getDomainConfig(): array
*/
public function getRobotsMetaTag(): string
{
- $currentDomain = $this->normalizeDomain(request()->getHost());
- $domainConfig = config("domains.domains.{$currentDomain}", []);
- $indexInGoogle = $domainConfig['index_in_google'] ?? false;
-
- // Park edilmiş domainler: noindex, follow
- // Bu sayede Google içeriği indexlemez ama link juice ana domain'e akar
- if (!$indexInGoogle) {
+ if (!TenantDomain::shouldIndex(TenantDomain::current())) {
return 'noindex, follow';
}
-
- // Ana domain: Veritabanından gelen robots ayarı varsa kullan
+
$global = $this->getGlobalSeo();
+
return $global['robots'] ?? 'index, follow';
}
+
+ private function toAbsoluteUrl(?string $path): ?string
+ {
+ if ($path === null || $path === '') {
+ return null;
+ }
+
+ if (str_starts_with($path, 'http://') || str_starts_with($path, 'https://')) {
+ return $path;
+ }
+
+ return rtrim(TenantDomain::baseUrl(), '/') . '/' . ltrim($path, '/');
+ }
}
diff --git a/app/Services/SitemapGenerator.php b/app/Services/SitemapGenerator.php
index b4b7ea8b..0a275f47 100644
--- a/app/Services/SitemapGenerator.php
+++ b/app/Services/SitemapGenerator.php
@@ -3,8 +3,8 @@
namespace App\Services;
use App\Models\WritesCategories\Category;
+use App\Support\TenantDomain;
use Carbon\Carbon;
-use Illuminate\Support\Facades\URL;
use Spatie\Sitemap\Sitemap;
use Spatie\Sitemap\Tags\Url as SitemapUrl;
@@ -15,9 +15,8 @@ class SitemapGenerator
public function __construct()
{
- // Get current domain from request or config
- $this->domain = request()->getHost() ?? parse_url(config('app.url'), PHP_URL_HOST) ?? 'localhost';
- $this->baseUrl = rtrim(request()->getSchemeAndHttpHost(), '/');
+ $this->domain = TenantDomain::current();
+ $this->baseUrl = TenantDomain::baseUrl();
}
public function generate(): void
@@ -25,7 +24,6 @@ public function generate(): void
$sitemap = Sitemap::create();
$now = Carbon::now();
- // Ana sayfa
$sitemap->add(
SitemapUrl::create($this->baseUrl)
->setLastModificationDate($now)
@@ -33,29 +31,40 @@ public function generate(): void
->setPriority(1.0)
);
- // Ana sayfalar (Sitelinks için önemli!)
- $mainPages = [
- '/writes' => 0.9,
- '/tests' => 0.9,
- '/certificates' => 0.9,
- '/categories' => 0.8,
- '/workspaces' => 0.8,
- ];
-
- foreach ($mainPages as $page => $priority) {
- try {
- $sitemap->add(
- SitemapUrl::create($this->baseUrl . $page)
- ->setLastModificationDate($now)
- ->setChangeFrequency('daily')
- ->setPriority($priority)
- );
- } catch (\Exception $e) {
- // Page might not exist
+ foreach (TenantDomain::sitemapRoutes() as $feature => $path) {
+ if (TenantDomain::isFeatureHidden($this->domain, $feature)) {
+ continue;
}
+
+ $sitemap->add(
+ SitemapUrl::create($this->baseUrl . $path)
+ ->setLastModificationDate($now)
+ ->setChangeFrequency('daily')
+ ->setPriority(0.9)
+ );
+ }
+
+ if (!TenantDomain::isFeatureHidden($this->domain, 'writes')) {
+ $this->addWrites($sitemap, $now);
+ }
+
+ if (!TenantDomain::isFeatureHidden($this->domain, 'tests')) {
+ $this->addTests($sitemap, $now);
+ }
+
+ if (!TenantDomain::isFeatureHidden($this->domain, 'certificates')) {
+ $this->addCertificates($sitemap, $now);
+ }
+
+ if (!TenantDomain::isFeatureHidden($this->domain, 'workspaces')) {
+ $this->addWorkspaces($sitemap, $now);
}
- // Kategoriler ve Yazılar
+ $sitemap->writeToFile($this->getSitemapPath());
+ }
+
+ private function addWrites(Sitemap $sitemap, Carbon $now): void
+ {
try {
Category::with('writes')->chunk(100, function ($categories) use ($sitemap, $now) {
foreach ($categories as $category) {
@@ -66,7 +75,6 @@ public function generate(): void
->setPriority(0.7)
);
- // Her kategorinin yazıları
foreach ($category->writes as $write) {
if ($write->status === 'published') {
$sitemap->add(
@@ -80,10 +88,12 @@ public function generate(): void
}
});
} catch (\Exception $e) {
- // Categories might not exist
+ // Categories might not exist for this tenant DB
}
+ }
- // Testler
+ private function addTests(Sitemap $sitemap, Carbon $now): void
+ {
try {
\App\Models\Tests\Test::where('status', 'published')
->chunk(100, function ($tests) use ($sitemap, $now) {
@@ -99,8 +109,10 @@ public function generate(): void
} catch (\Exception $e) {
// Tests might not exist
}
+ }
- // Sertifikalar
+ private function addCertificates(Sitemap $sitemap, Carbon $now): void
+ {
try {
\App\Models\Certificate::chunk(100, function ($certificates) use ($sitemap, $now) {
foreach ($certificates as $certificate) {
@@ -115,8 +127,10 @@ public function generate(): void
} catch (\Exception $e) {
// Certificates might not exist
}
+ }
- // Çalışma Alanları
+ private function addWorkspaces(Sitemap $sitemap, Carbon $now): void
+ {
try {
\App\Models\Workspace::chunk(100, function ($workspaces) use ($sitemap, $now) {
foreach ($workspaces as $workspace) {
@@ -131,40 +145,24 @@ public function generate(): void
} catch (\Exception $e) {
// Workspaces might not exist
}
-
- // Domain-specific sitemap dosyası
- $filename = $this->getSitemapFilename();
- $sitemap->writeToFile(public_path($filename));
}
- /**
- * Get domain-specific sitemap filename
- */
private function getSitemapFilename(): string
{
- // Sanitize domain for filename
- $safeDomain = str_replace(['.', ':'], '_', $this->domain);
-
- // For localhost or default, use sitemap.xml
- if (in_array($this->domain, ['localhost', '127.0.0.1', '::1'])) {
+ if (in_array($this->domain, ['localhost', '127.0.0.1', '::1'], true)) {
return 'sitemap.xml';
}
-
- // For production domains, use domain-specific filename
+
+ $safeDomain = str_replace(['.', ':'], '_', $this->domain);
+
return "sitemap_{$safeDomain}.xml";
}
- /**
- * Get sitemap path for current domain
- */
public function getSitemapPath(): string
{
return public_path($this->getSitemapFilename());
}
- /**
- * Get public sitemap filename (for URL)
- */
public function getPublicSitemapFilename(): string
{
return $this->getSitemapFilename();
diff --git a/bootstrap/app.php b/bootstrap/app.php
index 5f90bc86..3598e9ab 100644
--- a/bootstrap/app.php
+++ b/bootstrap/app.php
@@ -74,6 +74,10 @@
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
+ $middleware->web(prepend: [
+ \App\Http\Middleware\EnforceCanonicalHost::class,
+ ]);
+
$middleware->web(append: [
\App\Http\Middleware\HandleInertiaRequests::class,
\Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
diff --git a/config/domains.php b/config/domains.php
index 3db5cc4b..1c81d67f 100644
--- a/config/domains.php
+++ b/config/domains.php
@@ -6,8 +6,8 @@
| Main Domain
|--------------------------------------------------------------------------
|
- | The primary domain that should receive all SEO authority.
- | Parked domains will use canonical URLs pointing to this domain.
+ | Platform owner domain. Each tenant domain is indexed independently
+ | with its own DB, sitemap and canonical URLs.
|
*/
'main_domain' => env('MAIN_DOMAIN', 'checkupcodes.com'),
@@ -32,45 +32,37 @@
'yusufdur.com' => [
'name' => 'Yusuf Dur',
- 'type' => 'parked',
- 'index_in_google' => false,
+ 'type' => 'tenant',
+ 'index_in_google' => true,
'features' => ['writes', 'journey', 'certificates'],
'hidden_features' => ['workspaces', 'projects'],
- 'description' => 'Park edilmiş domain - noindex, follow stratejisi',
- 'seo_strategy' => 'noindex_follow',
- 'canonical_target' => 'checkupcodes.com',
+ 'description' => 'Tenant domain - bağımsız SEO',
],
'elselif.com' => [
'name' => 'Else If',
- 'type' => 'parked',
- 'index_in_google' => false,
+ 'type' => 'tenant',
+ 'index_in_google' => true,
'features' => ['writes', 'tests'],
'hidden_features' => ['workspaces', 'projects', 'journey'],
- 'description' => 'Park edilmiş domain - noindex, follow stratejisi',
- 'seo_strategy' => 'noindex_follow',
- 'canonical_target' => 'checkupcodes.com',
+ 'description' => 'Tenant domain - bağımsız SEO',
],
'candundarli.com' => [
'name' => 'Can Dündarlı',
'type' => 'tenant',
- 'index_in_google' => false,
+ 'index_in_google' => true,
'features' => ['all'],
'hidden_features' => ['workspaces', 'projects', 'journey'],
- 'description' => 'Tenant domain - noindex, follow stratejisi',
- 'seo_strategy' => 'noindex_follow',
- 'canonical_target' => 'checkupcodes.com',
+ 'description' => 'Tenant domain - bağımsız SEO',
],
'alperenalperen.com' => [
'name' => 'Alperen Alperen',
- 'type' => 'parked',
- 'index_in_google' => false,
+ 'type' => 'tenant',
+ 'index_in_google' => true,
'features' => ['all'],
- 'description' => 'Park edilmiş domain - noindex, follow stratejisi',
- 'seo_strategy' => 'noindex_follow',
- 'canonical_target' => 'checkupcodes.com',
+ 'description' => 'Tenant domain - bağımsız SEO',
],
// Localhost için
diff --git a/resources/views/app.blade.php b/resources/views/app.blade.php
index a8eae918..5f31b16e 100644
--- a/resources/views/app.blade.php
+++ b/resources/views/app.blade.php
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
+<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" prefix="og: https://ogp.me/ns#">
<head>
<meta charset="utf-8">
@@ -14,8 +14,10 @@
$canonicalUrl = $seoService->getCanonicalUrl();
@endphp
- <!-- Canonical URL (prevents duplicate content penalty) -->
+ <!-- Canonical URL -->
<link rel="canonical" href="{{ $canonicalUrl }}" />
+ <link rel="alternate" hreflang="{{ str_replace('_', '-', app()->getLocale()) }}" href="{{ $canonicalUrl }}" />
+ <link rel="alternate" hreflang="x-default" href="{{ $canonicalUrl }}" />
<!-- Primary Meta Tags -->
<meta name="description" content="{{ $meta['description'] }}">