Re: RewriteCond and negative matching

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Sun, Apr 13, 2025 at 11:21 PM Dave Wreski <dwreski@xxxxxxxxxxxxxxxxxxx.invalid> wrote:

Hi,

We're getting a ton of 404s for URLs for paths that don't exist, like /apps and other nonsense off the root that never existed that I'd like to redirect to the homepage.

Here's what I'm working with so far, but it redirects everything to the homepage, including valid articles. For example, here are two URLs that should be 200s:
https://linuxsecurity.com/news/security-trends/how-ai-is-shaping-the-future-of-linux-administration
https://linuxsecurity.com/news

# Allow the homepage
RewriteCond %{REQUEST_URI} ^/$ [OR]

# Allow specific directories and everything under them (abbreviated list for simplicity here)
RewriteCond %{REQUEST_URI} ^/(news|features|newsletters)(/.*)?$ [NC]

# If allowed, stop rewriting
RewriteRule ^ - [L]

# Otherwise, redirect to homepage
RewriteRule ^ https://linuxsecurity.com [R=301,L]

Everthing else, like https://linuxsecurity.com/apps should be redirected to the homepage. I've also tried negative matches, like the following.

RewriteCond %{REQUEST_URI}     !^/(news|features|newsletters)(/.*)?$ [NC]
RewriteRule    ^               https://linuxsecurity.com [L,R=301,QSD]

Ideas greatly appreciated.

Thanks,
Dave



If the "home page" is an index file in the documentroot, a simple FallbackResource will suffice, and you don't need to use mod_rewrite at all. 

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux