Download the PHP package illuminatech/url-trailing-slash without Composer

On this page you can find all versions of the php package illuminatech/url-trailing-slash. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package url-trailing-slash

Laravel URL Route Trailing Slash


This extension allows enforcing URL routes with or without trailing slash.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json.

Once package is installed you should manually register \Illuminatech\UrlTrailingSlash\RoutingServiceProvider instance at your application in the way it comes before kernel instantiation, e.g. at the application bootstrap stage. This can be done in 'bootstrap/app.php' file of regular Laravel application. For example:

Note: \Illuminatech\UrlTrailingSlash\RoutingServiceProvider can not be registered in normal way or be automatically discovered by Laravel, since it alters the router, which is bound to the HTTP kernel instance at constructor level.

In order to setup automatic redirection for the routes with trailing slash add \Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash middleware to your HTTP kernel. For example:

Heads up! Make sure you do not have any trailing slash redirection mechanism at the server configuration level, which may conflict with \Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash. Remember, that by default Laravel application is shipped with .htaccess file, which contains redirection rule enforcing trailing slash absence in project URLs. Make sure you adjust or disable it, otherwise your application may end in infinite redirection loop.

Usage

This extension allows enforcing URL routes with or without trailing slash. You can decide per each route, whether its URL should have a trailing slash or not, simply adding or removing slash symbol ('/') in particular route definition.

In case URL for particular route is specified with the trailing slash - it will be enforced for this route, and request without slash in the URL ending will cause 301 redirection. In case URL for particular route is specified without the trailing slash - its absence will be enforced for this route, and request containing slash in the URL end will cause 301 redirection.

For example:

Tip: the best SEO practice is having trailing slash at the URLs, which have nested pages, e.g. "defines a folder", and have no trailing slashes at the URLs without nested pages, e.g. "pathname of the file".

In case you have setup \Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash middleware, application will automatically redirect request with incorrect URL according to the routes definition. For the example above: request of http://example.com/items causes redirect to http://example.com/items/ while request to http://example.com/items/1/ causes redirect to http://example.com/items/1.

Heads up! Remember, that with this extension installed, you are controlling requirements of URL trailing slashes presence or absence in each route you define. While normally Laravel strips any trailing slashes from route URL automatically, this extension gives them meaning. You should carefully examine your routes definitions, ensuring you do not set trailing slash for the wrong ones.

Slash in Root URL

Unfortunally this extension is unable to handle trailing slashes for the project root URL, e.g. for a 'home' page. In other words \Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash middleware is unable to distinguish URL like http://examle.com from http://examle.com/. This restriction caused by PHP itself, as $_SERVER['REQUEST_URI'] value equals to '/' in both cases.

You'll have to deal with trailing slash for root URL separately at the server settings level.

Resource Routes

You can define trailing slash presence for resource URLs using the same notation as for regular routes. In case resource name is specified with trailing slash, all its URLs will have it. For example:

You can control trailing slash presence per each resource route using options 'trailingSlashOnly' and 'trailingSlashExcept' options. These ones behave in similar to regular 'only' and 'except', specifying list of resource controller methods, which should or should not have a trailing slash in their URL. For example:

Note: 'trailingSlashExcept' option takes precedence over 'trailingSlashOnly'.

Trailing Slash in Pagination

Unfortunately, the trailing slash will not automatically appear at pagination URLs. The problem is that Laravel paginators trim the trailing slashes from the URL path at the constructor level. Thus even adjustment of \Illuminate\Pagination\Paginator::currentPathResolver() can not fix the problem.

In case you need a pagination at the URL endpoint with a trailing slash, you should manually set the path for it, using \Illuminate\Pagination\AbstractPaginator::withPath(). For example:

Trailing Slash in Unit Tests

Since Illuminatech\UrlTrailingSlash\RoutingServiceProvider can not be registered as regular data provider, while writing unit and feature tests you will have to manually register it within test application before test kernel instantiation. This can be done within your \Tests\CreatesApplication trait:

However, this in not enough to make tests running correctly, because Laravel automatically strips trailing slashes from requests URL before staring test HTTP request. Thus you will need to override \Illuminate\Foundation\Testing\Concerns\MakesHttpRequests::prepareUrlForRequest() in the way it respects trailing slashes. This can be achieved using Illuminatech\UrlTrailingSlash\Testing\AllowsUrlTrailingSlash trait. For example:


All versions of url-trailing-slash with dependencies

PHP Build Version
Package Version
Requires illuminate/routing Version ^6.0 || ^7.7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package illuminatech/url-trailing-slash contains the following files

Loading the files please wait ....