Two Mod_rewrite Rules Clash

Alles, was den Apache betrifft, kann hier besprochen werden.

Two Mod_rewrite Rules Clash

Postby MCFC4Heatons » 04. August 2021 16:13

Hello, how do I combine these two mod_rewrite rules to work correctly, at the moment one rule will always fail depending on which order I put them in:

Code: Select all
    RewriteRule ^news/([^/\.]+)$ news\.php?cat=$1 [L]
             RewriteRule ^news/([^/\.]+)$ news-detail\.php?slug=$1 [L]
MCFC4Heatons
 
Posts: 5
Joined: 17. November 2018 00:47
XAMPP version: 5.6.38
Operating System: Windows 10

Re: Two Mod_rewrite Rules Clash

Postby Altrea » 04. August 2021 16:39

Hi,

It is technically impossible to resolve the same uri to two different destinations.
How should Apache know which destination is correct?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Two Mod_rewrite Rules Clash

Postby MCFC4Heatons » 04. August 2021 17:02

I see websites doing exactly this with urls like: /news/some-category and /news/some-article-title ..... How are they achieving this do you think?
MCFC4Heatons
 
Posts: 5
Joined: 17. November 2018 00:47
XAMPP version: 5.6.38
Operating System: Windows 10

Re: Two Mod_rewrite Rules Clash

Postby Altrea » 04. August 2021 20:23

Script based. Front controller design pattern.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Two Mod_rewrite Rules Clash

Postby MCFC4Heatons » 04. August 2021 21:03

I'm assuming thy are checking URL parameter for a match
MCFC4Heatons
 
Posts: 5
Joined: 17. November 2018 00:47
XAMPP version: 5.6.38
Operating System: Windows 10

Re: Two Mod_rewrite Rules Clash

Postby Nobbie » 05. August 2021 11:38

MCFC4Heatons wrote:I see websites doing exactly this with urls like: /news/some-category and /news/some-article-title ..... How are they achieving this do you think?


You must offer different matching patterns (first parameter of RewriteRule) in order to achieve that. But you have twice the same pattern, that does not work. In this case for example:

Code: Select all
RewriteRule ^news/some-category/([^/\.]+)$ news\.php?cat=$1 [L]
RewriteRule ^news/some-article/([^/\.]+)$ news-detail\.php?art=$1 [L]


If you tell us more about your infrastructure, we could work out a working redirect.
Nobbie
 
Posts: 13165
Joined: 09. March 2008 13:04


Return to Apache

Who is online

Users browsing this forum: No registered users and 244 guests