Hello Everybody, ive searched everywhere before posting as issue here.
if i am doing it wrong (i am sorry )please be kind as i am trying to solve that since one week without success.
Inserting a RewriteRule in .htaccess custom redirects (after common exploits before J! core SEF) results in a redirect to 404 if the redirecting is not a physical file or existing path.
so for example:
in .htaccess
RewriteRule ^testslugview/(.*) index.php?option=com_content&view=$1 [L,NC] >> 404 message
RewriteRule ^testslug index.php?option=com_content&view=featured [L,NC] >> 404 message
RewriteRule ^realfilejs/(.*) templates/cassiopeia/js/$1 [L,NC] >>OK
RewriteRule ^realfilecss/(.*) templates/cassiopeia/css/$1 [L,NC] >> OK
End Custom redirects
expected result is the featured view list of com_content or at least a component error.
# | Function | Location
1 | () | JROOT/libraries/src/Router/Router.php:153
2 | Joomla\CMS\Router\Router->parse() | JROOT/libraries/src/Application/CMSApplication.php:1003
3 | Joomla\CMS\Application\CMSApplication->route() | JROOT/libraries/src/Application/SiteApplication.php:775
4 | Joomla\CMS\Application\SiteApplication->route() | JROOT/libraries/src/Application/SiteApplication.php:225
5 | Joomla\CMS\Application\SiteApplication->doExecute() | JROOT/libraries/src/Application/CMSApplication.php:231
6 | Joomla\CMS\Application\CMSApplication->execute() | JROOT/includes/app.php:63
7 | require_once() | JROOT/index.php:36
tryed almost everywhere , and those results happen only on Joomla4 beta /1 /2 /3 /4
ubuntu 18.04 with php 7.2 | 7.3 | 7.4
Thanks everybody and sorry in advance if all that mess is because of my fault.
Labels |
Added:
?
|
Title |
|
Please try
[R=301,L,NC]
instead of
[L,NC]
[L,NC]
gives always a 404. Also on Joomla 3. That's a server thing.
[R=301,L,NC]
Hello @ReLater Thank you for your answer , but R=301 will perform a 301 Redirect, the url will not be rewrited but truly Redirected
[L,NC]
gives always a 404. Also on Joomla 3. That's a server thing.
Sorry, no i have 25 websites with [L,NC] on production J3 Websites.. and no 404 Exceptions
Update:
I have modified the Router.php to fullfill my needs, but im sure that my code is ugly as hell. (i will post it shameless down below)
anyway ive understand why "custom rewriting rules to index.php" on htaccess is not working anymore in J4
in the old Router (J3.x) as already stated above the parse function check for $vars['option']
before triggering an Exception to 404.
this is not the case in J4! because the exception is fired as soon at the code understand that length of $uri->getPath()) > 0)
is not empty/zero. I have tried to override/bypass/implements in the component routing but without success as because the stack interrupt the routing (firing exception) way before reaching the custom routing rules on component.
this is the ugly code ive wrote to bypass the problem for the moment:
if (\strlen($uri->getPath()) > 0 && $uri->getVar('query') == NULL)
{
$opt = Factory::getApplication()->input->getString('option',false);
if(!$opt) {
throw new RouteNotFoundException(Text::_('JERROR_PAGE_NOT_FOUND'));
}
}
and that said my skills regarding joomla code are over
Please, someone with more skills is needed here because i still not understand if this is an issue or if its me that do not code properly on joomla.
Hello Folks!
someone with more skills can give a check on this and clarify if this is an issue?
Hi @HLeithner , yep!
Consider that in htaccess " ^seftext/sefvar index.php?option=com_content&view=featured "
object(Joomla\CMS\Uri\Uri)#672 (10) { ["uri":protected]=> string(53) "http://domain/seftext/sefvar" ["scheme":protected]=> string(4) "http" ["host":protected]=> string(19) "domain.com" ["port":protected]=> NULL ["user":protected]=> NULL ["pass":protected]=> NULL ["path":protected]=> string(18) "seftext/sefvar" ["query":protected]=> NULL ["fragment":protected]=> NULL ["vars":protected]=> array(3) { ["option"]=> string(11) "com_content" ["view"]=> string(8) "featured" ["Itemid"]=> int(101) } }
Hello Coders..
ive maked many tests and all .htaccess files i have in 35 J!3.9x websites does not work with currently J!4 (tested up to beta 6) Route.php lib.
someone can help us flagging this as Issue?
1 year and still open?
can someone take a look at it?
I tried it in j3 and it didnt work there either
I tested it in 3 and it worked... A redirect is something different then then the requested rule.
So the question is if j4 can be changed so it works.
@Hackwar is this expected behavior?
Short:
Yes, this is expected behavior.
Long:
If we comment that line in the router, we re-introduce the problem that invalid URLs still give a 200 code. Example would be: /this-is-a-valid-url
is okay, but with this change /this-is-a-valid-url/something-else
would still return the same page and give a 200 code. That is why we can't simply comment that. Since it seems as if this redirect messes up the environment variables, this seems not be possible. The proper way would be to redirect to the right SEF URL...
ok, sound reasonable. I looked at the relevant code line and saw that all ParseRules are processed before this check so it would be possible to write a plugin and clean the path before it reaches this check.
@ceciogit is this enough for you?
the system plugin could be something like:
<?php
class plgSystemSEFHACK extends \Joomla\CMS\Plugin\CMSPlugin
{
protected $app;
public function onAfterInitialise()
{
// this rule is only relevant for the frontend
if ($this->app->isClient('site')) {
$router = $app->getRouter();
$router->attachParseRule(array($this, 'parseRule'), \Joomla\CMS\Router\Router::PROCESS_AFTER);
}
}
public function parseRule(&$router, \Joomla\CMS\Uri\Uri &$uri)
{
if (\strlen($uri->getPath()) > 0)
{
$uri->setPath('');
}
}
}
That's only a PoC and hasn't been tested also I can't say what side effects this would generate. Maybe you should check if the option is com_content or the path is the same as in your htaccess file.
I think that should solve your problem and I close this ticket as expected behavior including a custom solution.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-02-24 09:38:06 |
Closed_By | ⇒ | HLeithner | |
Labels |
Added:
No Code Attached Yet
Removed: ? |
Sorry for being Late on answering you guys, but had lot issue in those months.
Thank you @HLeithner @brianteeman and @Hackwar
Update:
Commenting following lines of Joomla\CMS\Router the rewriteRule work again.
// Check if all parts of the URL have been parsed.
// Otherwise we have an invalid URL
151
if (\strlen($uri->getPath()) > 0)
152
{
153
// Commenting Here will work again (this is different from J!3.9x need to check )
154
// throw new RouteNotFoundException(Text::_('JERROR_PAGE_NOT_FOUND'));
155
}
But obviously commenting like that means that every non parsed or zero length $uri->getPath() will be redirected to index.php without Firing Exception ..
it seems that in j3.9x " Router > parse() " fire the 404 exception only if all of those 3 are true :
strlen($uri->getPath()) > 0
array_key_exists('option', $vars)
ComponentHelper::getParams($vars['option'])->get('sef_advanced', 0)
i think i have lost something on the road to j4 ..