I am using Joomla 4. I have a requirement to rewrite certain URLs to a specific article (article with ID 32). This worked OK with Joomla 3 but now I am getting unexplained error 404 using the same .htaccess rewriterules.

For example, if the original URL is example.com/foo then the .htaccess file will rewrite it to example.com/index.php?option=com_content&view=article&id=32 and then the user will have this article displayed.

However, if I enter example.com/foo I get an error 404.

The target URL seems to work if I paste it into the address bar on the browser (ie. if I paste in example.com/index.php?option=com_content&view=article&id=32) but if I try example.com/foo it fails.

I have tested the rewrite condition and rule by changing the target to another address on the page (to a static html page eg. example.com/Essay/foo.html) and this works OK.

These are the rewrite condition and rule that I am using:

RewriteCond %{REQUEST_URI} ^/foo$
RewriteRule .* /index.php?option=com_content&view=article&id=32 [L]

I have also checked $_SERVER['REQUEST_URI'], and $_SERVER['REDIRECT_URL'] and $_SERVER['QUERY_STRING'] and they appear to be OK, and the same whether I enter /foo or /index.php?option=com_content&view=article&id=32

Original URI: /foo
Modified URI: /index.php
Query String: option=com_content&view=article&id=32

If I use the flags [R=301,L] instead of just [L] then the redirection takes place to the article 32. However we need to keep the original URL which is why we just use [L] in the rewrite rule. This worked OK in Joomla 3 but not in Joomla 4 for some reason.

Any suggestions or help would be most welcomed!

  • Are you on the same server/config as when using Joomla 3? Where exactly in your .htaccess file have you placed this rule?
    – MrWhite
    Commented Dec 4, 2023 at 0:39
  • It is on the same server/config. We've put the rewrite cond and rule in the section of the standard htaccess where the comments indicate the custom rewrites are intended (inside the test that mod rewrite is enabled and just after the tests for common exploits) Commented Dec 4, 2023 at 2:09
  • Thank you Terry for the re-write and formatting of the question , and apologies for not having done that in the first place! Commented Dec 8, 2023 at 2:36


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.