Help needed to create rewrite rule that bypasses some rules

 
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting
View previous topic :: View next topic  
Author Message
JMMotyer
-


Joined: 06 Jul 2005
Posts: 60
Location: Burlington (Toronto-ish), Ontario, Canada

PostPosted: Tue Jan 17, 2023 7:05 am    Post subject: Help needed to create rewrite rule that bypasses some rules Reply with quote

Hello, folks,

I am hoping that someone can help me with creating a new Rewrite Rule, as the rule formats are beyond my capability.

Please let me explain what I already have. The following screenshot shows my current Rewrite Rules, all of which have worked flawlessly for the past year:



The 1st rule just redirects all non-WWW to WWW.

Because of the last 4 rules (which I will get to shortly), the 3 Global rules allow me to not have to specify in the URL the actual filename & extension, and instead I can just enter in the 3 aliases, and those 3 rewrite rules point to the actual filenames & extensions.

The reason for the last 4 rewrite rules, is that this host is running a Photo Gallery script that is written for Apache, and which uses & requires an htaccess file. As Abyss does not use htaccess files, Aprelium was able to convert that script's htaccess file into the last 4 rewrite rules in the screenshot.

Again, all of the rewrite rules have worked flawlessly for nearly a year. Which brings me to what I am hoping someone can help me with, and that it is even possible for me to do.

I have another alias called /pages , and that alias points to a folder that contains a few .php files (which contain just HTML code with some PHP code, hence the PHP extension).

When I go to domain.com/pages/filename.php , the last 4 (htaccess-equivalent) rewrite rules act, and the Photo Gallery script gives an error that the page cannot be found.

So my question is, is it possible for me to add another rewrite rule, that is run BEFORE the last 4 (htaccess-equivalent) rewrite rules?

I would like to be able to access, for example:

    domain/pages/filename1.php
    domain/pages/filename2.php
    domain/pages/filename3.php
    etc.

Hopefully this is possible, and any help allowing me to create that rule would be greatly appreciated.

Thank you in advance & have yourselves a great day.

Regards & be safe,
John
Back to top View user's profile Send private message Visit poster's website
Horizon
-


Joined: 18 Feb 2022
Posts: 54

PostPosted: Wed Jan 18, 2023 9:56 pm    Post subject: Reply with quote

Hello,
Ideally what we need for bypassing other rules is a new 'Do nothing' action for URLRewrite rules.

This way we could match the pattern (RegEx) for your /pages URLs with a 'do nothing' action followed by 'stop matching'.

However we don't have this yet, so I can suggest another way.

You could make one internal redirect followed by 'Stop matching':

- relative to base: /
- path: pages(?:\/.*|)$

- condition: not case-sensitive
* QUERY_STRING - does not contain: random_unique_text

* uncheck 'apply to subrequests'

- action: internal redirect
* redirect to: %{REQUEST_FILENAME}?random_unique_text
* append query string

- then: stop matching

That's the rule you can place right above the last 4 rules such that URLRewrite stops matching past it.

random_unique_text cans be for example 383806a70bbae1ededda87558964ff3d.

This random text is used to prevent infinite loops.
This URLRewrite rule is actually a dummy rule that does nothing significant, and it's used just for the 'Stop matching' function to halt the URLRewrite before the last 4 rules.

This should work, the logic behind it surely works even if my example rule might need to be corrected (typos, etc).

However, you will have to edit the last 4 URLRewrite rules and uncheck the 'apply to subrequests' for them if checked.

And because the redirect of the rule I suggested passes through URLRewrite again as a subrequest, it becomes immune to that dummy redirect and the last 4 rules which don't apply to subrequests.
Back to top View user's profile Send private message
JMMotyer
-


Joined: 06 Jul 2005
Posts: 60
Location: Burlington (Toronto-ish), Ontario, Canada

PostPosted: Thu Jan 19, 2023 2:22 am    Post subject: Reply with quote

Quote:
You could make one internal redirect followed by 'Stop matching':

Perfect! Works like a charm :-).

Code:
However, you will have to edit the last 4 URLRewrite rules and uncheck the 'apply to subrequests' for them if checked.

I made sure to uncheck those 4 rules, thank you.

The only thing that I wasn't sure of was Escape Redirection Location, which I left checked. Don't know if it should be enabled or disabled, but everything seems to work fine with it enabled.

I'm sorry to always be a pest with these request for help with rewrite rules, but I am too old these days to grasp the format of these rules, such as (?:\/.*|)$ , etc.

Thanks again, Horizon, and have yourself a great day.

Regards & be safe,

John
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group