Re: RewriteCond and negative matching

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

 





On Mon, Apr 14, 2025 at 12:17 PM Dave Wreski <dwreski@xxxxxxxxxxxxxxxxxxx.invalid> wrote:

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.

I believe that only works for physical files, like /images/myimage.gif, and not for virtual paths set up by Joomla, like /news/myarticle.html, correct?

I tried just adding it in the VirtualHost, but would like it to work for specific paths, not for any link that doesn't exist on the entire site.

Thanks,
Dave

If you need the complexity of mod_rewrite, I would start by using the rewrite log to troubleshoot.
This will allow you to see the requested URI path, and rewritten path, if applicable.

Yes, here is that relevant output, although I don't understand how it's failing.

RewriteCond: input='/news/security-trends/how-ai-is-shaping-the-future-of-linux-administration' pattern='^/$' => not-matched
RewriteCond: input='/news/security-trends/how-ai-is-shaping-the-future-of-linux-administration' pattern='^/(news|features|newsletters)(.*)?$' [NC] => matched
pass through /news/security-trends/how-ai-is-shaping-the-future-of-linux-administration
add path info postfix: /var/www/vhost/html/news -> /var/www/vhost/html/news/security-trends/how-ai-is-shaping-the-future-of-linux-administration

Here again is the rewrite rule. The pattern matched correctly, so it should just result in a 200, but it instead is redirecting. I believe the problem is with the first rewriterule, as it is the second one that is causing the redirect. It appears that the first rewriterule is not enough for it to stop processing rules altogether. Instead, it continues on to the second one anyway.

# 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]




If you're using .htaccess files, those are re-processed over and over and over and over until it stops matching.

You should not be using .htaccess files, unless you have no other choice in the matter.  If that is the case, consider adding RewriteCond directives before every relevant RewriteRule directive. 

[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