-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Url rewrites #373
Open
johanjanssens
wants to merge
16
commits into
master
Choose a base branch
from
feature/372-rewrite
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Url rewrites #373
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This allows pages to be to redirect any url, anywhere, even when not in a page context.
identifiers by a custom scheme and rename 'pages' scheme to 'page'
The callback is defined is as follows: 'function($route, $generate = false)' - $route: a ComPagesDispatcherRouteRouteInterface object - $generate: are we generating a url or resolving (default false) Callbacks are both supported for static and dynamic routes, in case of a dynamic route the callback is called only if the route could be succesfully resolved.
Example: '/path/to/page' => [ 'generate' => function($route) { return true; }, 'resolve' => function($route) { return true; } ],
…r redirect method
- Add 'slug' expression constraint - If the target contains a contraint the target segment will be filtered acoordingly
- Add 'id' type - Do not use a match group for 'slug' type
# Conflicts: # code/site/components/com_pages/dispatcher/http.php # code/site/components/com_pages/resources/config/site.php
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR closes #372 and implements a specialised rewrite router for url's generated by the Joomla router.
The url rewrite router offers support for both pattern and callback based routing. It removes the need for complex SEF extensions, allows to easily define custom rewrite rules and handles redirects automatically.
Rewrite routing is available globally, rewrites can be setup outside of the context of Pages for any url on your Joomla site
Adding routes
Routes are defined in the configuration through the new
rewrites
config option.Rewrite redirects
The router will automatically handle redirects from old to new url's for defined rewrites, if the rewrite is updated or removed it will also handle rewrites from new to old url's. This ensure that regardless of the rewrites being setup page authority is retained.
Match types
Following new match types have been added to make it easy to match urls with id's and remove id's from urls.
id
:1-my-article-title
slug
:my-article-title
An
id
type MUST start with a number followed by a dash-
while anslug
MUST start with a letter.Following are all valid id's:
Following are all valid slugs:
Filtering routes
The router is now also capable of filtering route targets. If a target segment includes a constraint it will be filtered accordingly. This allows to transform the url segments easily.
For example, the following rewrite rule will match a segment that starts with an
id
and filter it leaving only theslug
in the rewrite:'news/[id:article]' => 'news/[slug:article]'
Example: Removing id's
The following rewrite route will remove id's from the url's for the news menu item in Joomla. We are providing the
slug
constraint here too in the target url, which will filter out theid
from the actual slug.http://example.com/news/1-company/2-about-covid
http://example.com/news/company/about-covid
Example: Shortening url's
The following rewrite route will create a short url, removing the category from the url, but retaining the article id. This ensures the url is unique.
http://example.com/blog/1-products/2-announcement
http://example.com/blog/2-announcement
The following rewrite route will create a short url, removing the category from the url, and also removing the article id. In this case you need to ensure the article slug is unique.
http://example.com/blog/1-products/2-announcement
http://example.com/blog/announcement
Global configuration
You do not need to setup a
/joomlatools-pages
folder to be able to define rewrite routes. If you just want to use this feature add aconfiguration-pages.php
to your Joomla root, and defines your rewrite routes there, they will just work.