logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: RewriteRule not working after 5th rule
Author
sdbhabal



Joined: 25 Dec 2014
Posts: 3
Location: India, Thane

PostPosted: Thu 27 Jun '24 9:19    Post subject: RewriteRule not working after 5th rule Reply with quote

Hello Experts,

I am stuck in a viard issue.
I have the below set of RewriteRule configured in httpd.conf for one of my domain.

----
<Directory "/var/www/html/test/">
RewriteEngine On
RewriteRule ^/?([-a-zA-Z0-9_+]+)$ short/1.php?d=$1 [L,NC]
RewriteRule le/?([-a-zA-Z0-9_+]+)$ short/2.php?d=$1 [L,NC]
RewriteRule lo/?([-a-zA-Z0-9_+]+)$ short/3.php?d=$1 [L,NC]
RewriteRule l/?([-a-zA-Z0-9_+]+)$ short/4.php?d=$1 [L,NC]
RewriteRule w/?([-a-zA-Z0-9_+]+)$ short/5.php?d=$1 [L,NC]
RewriteRule s/?([-a-zA-Z0-9_+]+)$ short/6.php?d=$1 [L,NC]
RewriteRule n/?([-a-zA-Z0-9_+]+)$ short/7.php?d=$1 [L,NC]
require all granted
</Directory>
----

The rule after the 5th rule is not working in the above rule set.
In my case, the rules below are not working.

RewriteRule s/?([-a-zA-Z0-9_+]+)$ short/6.php?d=$1 [L,NC]
RewriteRule n/?([-a-zA-Z0-9_+]+)$ short/7.php?d=$1 [L,NC]

Both these rules give the same output like 5th rule.
I also shuffled the rules up and down still any rules after 5th rule are not working as expected.
I don't know what I am doing wrong or missing anything, any help will be highly appreciated.
Please advise.

Thanks and regards,
sdbhabal.
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 342
Location: UK

PostPosted: Mon 01 Jul '24 20:56    Post subject: Reply with quote

I've been unable to reproduce your RewriteRule problem in a test environment (Apache 2.4.59). For me, any number of sequential RewriteRules can be made to trigger, using appropriate test URLs.

However, I am somewhat confused by your regular expression constructs, and would suggest you check they match what you're expecting (I use https://regex101.com to test regular expressions - using the PCRE2 flavour).

Only your first RewriteRule regex contains a start of line anchor (^). Is that intentional?
Secondly, in all rules your forward slash is followed by a question mark (?), which therefore matches 0 or 1 forward slashes. Again, is that intentional (specifically 0 matches)?

A combination of these two constructs means any number of two characters sub-strings will match, depending on their position within a string.

To help. can you provide a list of sample URLs for your site, which you need to match your various RewriteRules.

Further, I'd turn up debugging for rewrite events, so you can see what's happening (in the Apache error.log file). Add the following to your configuration file:
Code:

LogLevel warn rewrite:trace6
Back to top


Reply to topic   Topic: RewriteRule not working after 5th rule View previous topic :: View next topic
Post new topic   Forum Index -> Apache