-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 Rewriting Module #16687
base: main
Are you sure you want to change the base?
URL Rewriting Module #16687
Conversation
Fork update
Sync with upstream repository
Sync with upstrem repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arkadiuszwojcik Thank you for this PR.
I am not a fan of the suggested UI. I think it would be much better and user friendly to have a UI similarity to the Tenants, Features, or Notifications UI where user can add a new rule "as a new entry" form.
Also add a way to edit one rule at a time. I also think it would be better to prompt the user with at the following fields:
- Title
- Description
Pattern
Replacement
SkipRemainingRules
.
Or the following fields:
- Title
- Description
Pattern
SkipRemainingRules
.
This way the user can provide meaning title/description for what the rules should actually do.
And even better, you can then easily implement sorting on the UI where one can drag/drop the entries which will change the order of the entries in the options.
Updated
I would rename the module to UrlRewriting
Also, how would this work with other tenants?
For example, if every tenant on my setup uses a subsdomain, can one tenant put a rule that would redirect all of the traffic to their instance instead?
.AddRedirect("^(?!www\\.).*", "https://site1.example.com", statusCode: StatusCodes.Status301MovedPermanently)
Or of every tenant is setup using a prefix, can I just write a rule that would redirect all other tenants to my instances?
.AddRedirect(@"^(.+)/$", "/site1/")
Please confirm that the two rules I shared above, are only applicable on one tenant only and will not impact other tenants.
src/OrchardCore.Modules/OrchardCore.Rewrite/Drivers/RewriteSettingsDisplayDriver.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Rewrite/Drivers/RewriteSettingsDisplayDriver.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Rewrite/Drivers/RewriteSettingsDisplayDriver.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Rewrite/Drivers/RewriteSettingsDisplayDriver.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Rewrite/Views/RewriteSettings.Edit.cshtml
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Rewrite/Views/_ViewImports.cshtml
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Rewrite/OrchardCore.Rewrite.csproj
Outdated
Show resolved
Hide resolved
@MikeAlhayek, thank you for your comments. Regarding the UI, I think the module should ultimately support both types of URL rewrites: UI-based and text-based. Text-based is more advanced because RewriteRule can be preceded by multiple RewriteCond, which allow for numerous checks based on variables like Cookie, DateTime, UserAgent, etc. These checks are complex to model in a graphical UI. I suggest having two tabs: one for "Simple Mode" with a user-friendly interface, and another for "Advanced Mode". In this PR I just added only advance one. Regarding multitenancy, the URL rewrite middleware is registered separately for each tenant (each tenant has its own IApplicationBuilder instance), so when a request hits the rewrite middleware, it has already been routed to the proper tenant by OC. I tested a simple case with two tenants to verify that the rewrite rules from one do not affect the other. With this it is impossible to intercept and redirect traffic from other tenant. |
@arkadiuszwojcik yes I understand. You can also model your UI just like Queries UI. This UI allows you to add different types of queries. In your case you can provide the advance rule, but will allow another person to also define a different rule. Yea the renaming should work as long as the middleware is added after the tenant middle ware. |
Regarding the module name, what do you think about 'UrlRewrites' instead of 'UrlRewriting'? To me, it seems much more aligned with the current module names, although I might be wrong. |
Personally, I would go with |
Is there any reason not to use the URL Rewrite module available in ASP.NET Core? Regardless the issue that you mentioned |
Can you elaborate? This OC module is using ASP.NET Core Rewrite module internally, it just expose way to provide rewrite rules in OC admin menu. Update: |
Good, also I have another module on top of my head that might be related URL redirection |
src/OrchardCore.Modules/OrchardCore.UrlRewriting/Drivers/UrlRewritingSettingsDisplayDriver.cs
Outdated
Show resolved
Hide resolved
- Permissions refactor work
- Rename Permissions class to UrlRewritingPermissionProvider
This pull request has merge conflicts. Please resolve those before requesting a review. |
@arkadiuszwojcik when you are done addressing my previous feedback, please request my review and I'll review this again. |
@MikeAlhayek everything is fixed except suggested UI ... so will it be accepted as it is or should I mark is as draft and start working on more user frendly UI? |
I would rather see the improved UI first. If you don't want to spend lots of time on it, I understand. I would at minimum like to see the UI layout similar to the Queries UI. Once that is ready, please request my review and I'll test it out and provide you feedback. |
@MikeAlhayek took me a while but I managed to crate first version of UI for this module. You can create first rule by editing some recipe by adding dependency to module:
and creation step:
This rule allow to access images by |
|
||
public sealed class AdminMenu : AdminNavigationProvider | ||
{ | ||
public readonly IStringLocalizer S; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public readonly IStringLocalizer S; | |
internal readonly IStringLocalizer S; |
builder | ||
.Add(S["Configuration"], configuration => configuration | ||
.Add(S["URL Rewriting"], S["URL Rewriting"].PrefixPosition(), rewriting => rewriting | ||
.AddClass("urlrewriting").Id("urlrewriting") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.AddClass("urlrewriting").Id("urlrewriting") | |
.AddClass("urlrewriting") | |
.Id("urlrewriting") |
src/OrchardCore.Modules/OrchardCore.UrlRewriting/Controllers/AdminController.cs
Outdated
Show resolved
Hide resolved
return View(shape); | ||
} | ||
|
||
[HttpPost, ActionName(nameof(CreateRule))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[HttpPost, ActionName(nameof(CreateRule))] | |
[HttpPost] | |
[ActionName(nameof(CreateRule))] |
return View(model); | ||
} | ||
|
||
[Admin("UrlRewriting/CreateRule", nameof(CreateRule))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Admin("UrlRewriting/CreateRule", nameof(CreateRule))] | |
[Admin("UrlRewriting/CreateRule", "CreateRewritingRule")] |
src/OrchardCore.Modules/OrchardCore.UrlRewriting/Views/Admin/Index.cshtml
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.UrlRewriting/Views/Admin/Index.cshtml
Outdated
Show resolved
Hide resolved
</div> | ||
</form> | ||
|
||
<script at="Foot" depends-on="jQuery"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you can, please don't use jQuery. we are trying to remove jQuery from all of our views
src/OrchardCore.Modules/OrchardCore.UrlRewriting/Views/Admin/Index.cshtml
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.UrlRewriting/Views/_ViewImports.cshtml
Outdated
Show resolved
Hide resolved
@arkadiuszwojcik I am going to push some changes to your branch. The display driver need a bit of work. I don't have time now to refactor it. But here is a general feedback on what needs to be done there:
this way you are not using key like
This is what we have in the queries UI. When you click "Add Query", you'll get a modal where you can select which query type to create. In your case it would be rule type. Then each query type would have a very simple UI for that rule time without the show/hide and all these properties. |
@arkadiuszwojcik I am making changes to this PR. please don't make any changes. this will improve the PR |
@arkadiuszwojcik I made lots of changes to your PR. The PR now uses the same UI as Queries so it is easily extensible. To add new rules, all you need is to implement the following
Here is what you need to do
|
This PR partially addresses issue #9027. It introduces a new Rewrite module with, as of now, basic functionality that allows providing rewrite/redirect rules using Apache mod_rewrite syntax. This functionality is very basic but also very flexible, providing a good starting point for more features that might be requested in the future.
Few remaining questions are: