Skip to content

Commit 6e1f0d7

Browse files
Correct namespaces
1 parent dd2cd0d commit 6e1f0d7

4 files changed

+30
-3
lines changed

readme.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@
33
[![Latest Version on Packagist][ico-version]][link-packagist]
44
[![Total Downloads][ico-downloads]][link-downloads]
55
[![Build Status][ico-travis]][link-travis]
6-
[![StyleCI][ico-styleci]][link-styleci]
76

87
It is important to remove trailing slashed from applications made with laravel and it is bad for SEO as Google registers page twice, once with slash and once without it. The correct behaviour is to create 301 for ever page with trailing slash to avoid content duplication in search results.
98

109
Here is the source: https://developers.google.com/search/blog/2010/04/to-slash-or-not-to-slash
1110

11+
## Before you start
12+
13+
An easy way to check if your app is behaving properly would be to create a test route in ``routes/web.php`` like this:
14+
15+
```
16+
Route::get('/foobar', function () {
17+
return 'This is not good!';
18+
});
19+
```
20+
21+
Then visit this endpoint with trailing slash ``yourapp.test/foobar/``
22+
23+
If "This is not good!" was displayed and trailing slash did not dissapear from your url in the browser then Google will not be happy about it.
24+
1225
## Installation
1326

1427
Via Composer
@@ -19,6 +32,12 @@ $ composer require aurawindsurfing/slashremovemiddleware
1932

2033
## Usage
2134

35+
This package will auto register itself in Laravel 6 and higher.
36+
37+
Now repeat the same test and you should be redirected to the same url but without trailing slash ``yourapp.test/foobar`` and see the same text.
38+
39+
Now Google will not index every single page of your app twice.
40+
2241
## Change log
2342

2443
Please see the [changelog](changelog.md) for more information on what has changed recently.

src/Http/Middleware/SlashRemoveMiddleware.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Aurawindsurfing\SlashRemoveMiddleware;
3+
namespace Aurawindsurfing\SlashRemoveMiddleware\Http\Middleware;
44

55
use Closure;
66
use Illuminate\Support\Facades\Redirect;

src/SlashRemoveMiddleware.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Aurawindsurfing\SlashRemoveMiddleware;
4+
5+
class SlashRemoveMiddleware
6+
{
7+
// Build wonderful things
8+
}

src/SlashRemoveMiddlewareServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function boot(): void
2424
public function register(): void
2525
{
2626
$kernel = $this->app->make(Kernel::class);
27-
$kernel->pushMiddleware(SlashRemoveMiddleware::class);
27+
$kernel->pushMiddleware(\Aurawindsurfing\SlashRemoveMiddleware\Http\Middleware\SlashRemoveMiddleware::class);
2828
}
2929

3030
/**

0 commit comments

Comments
 (0)