Joomla 4 dynamic url bug report and procedures to produce it
Step 1. Create an article "History"
Step 2. Create a hidden menu "History" with
Menu Item Type = Single Article
Select Article = "History" article created in step 1
Step 3: In Admin panel, set
Search Engine Friendly URLs = Yes
Use URL Rewriting = Yes
Step 4: in .htaccess, add
RewriteRule ^history/([^-])-?(.).html$ index.php/history?q=$1&page=$2 [NC,L]
Note, this RewriteRule works for both https://www.mydomain/history/123.html (page = 0 ) and https://www.mydomain/history/123-1.html (page = 1)
Step 5: The following urls produces "404 Page not found"
https://www.mydomain/history/123.html
https://www.mydomain/history/123-1.html
Step 5: Workaround: Edit libraries/src/Router/Router.php as bellow, the urls work as expected
public function parse(&$uri, $setVars = false) { // Do the preprocess stage of the URL parse process $this->processParseRules($uri, self::PROCESS_BEFORE); // Do the main stage of the URL parse process $this->processParseRules($uri); // Do the postprocess stage of the URL parse process $this->processParseRules($uri, self::PROCESS_AFTER); // Check if all parts of the URL have been parsed. // Otherwise we have an invalid URL if ( \strlen( $uri->getPath() ) > 0 ) { $vars = $uri->getQuery(true); if ( array_key_exists( "Itemid", $vars ) ) { $table = \JTable::getInstance( "Menu" ); $table->load( [ "id" => $vars[ "Itemid" ] ] ); // trying to redirect to home page when getPath() is not empty, page doesn't exists! if ( $table->home == 1 ) { throw new RouteNotFoundException(Text::_('JERROR_PAGE_NOT_FOUND')); } } } if ($setVars) { $this->setVars($uri->getQuery(true)); return $this->getVars(); } return $uri->getQuery(true); }
Expect to obey the rewrite rule
404 Page not found
Centos 8 & 9
php version 7.4.33 & 8.0.27
Joomla 4 version: all versions
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
Labels |
Added:
bug
|
Sorry, I thought people ignore the previous report, which was quiet some time ago.
This one probably has more detailed steps to produce the bug.
Not sure why you need to do this but it seems like you are trying to work around a component that is missing a complete router?
I don't actually know what is the correct fix as it is a big system. I just post my workaround as a reference so the developer can dig into the issuer quicker. So far this workaround works.
Joomla 3 had the same issuer. I reported it and it got fixed pretty quick. Don't know why this bug comes back in Joomla 4....
The question is if it is a core bug. I have read the opening comment several times and don't understand what your goal is. What is your purpose?
Joomla 3 had the same issuer. I reported it and it got fixed pretty quick.
Do you have a reference/link to that issue or pr that led to the fix in J! core?
if i understand correctly the goal is to convert a url that is in the format history?q=$1&page=$2 to history/$1-$2
but to my eyes that is a task for the router and not a rewrite rule.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-02-23 13:18:14 |
Closed_By | ⇒ | Hackwar |
@vicn1222 thank you for reporting this to the project. I do see what you are trying to do, but I fear I have to agree with @brianteeman here. What you are trying to do is something that you would have to do with additional code in the application router, not with a rewrite rule. We will unfortunately not change the router in the way you are requesting.
I am surprised this bug is closed without action.
The goal is to convert the following url with parameters
https://www.mydomain/history?q=123&page=1
into a search engine friendly url as below through .htacess. This rewrite is supported by Apache. But Joomla's bug prevents this Apache's functionality.
https://www.mydomain/history/123-1.html
Can someone please re-open it?
Thank you!
Frank
No, what you are doing is trying to interfer with the routing code of Joomla. There are good ways to achieve what you are trying to do by extending the routing code of Joomla, but what you are trying to do is not one of them. We will not open this back up again.
@Hackwar Before I convert my site into Joomla, I put that rewrite rule in .htaccess. Apache automatically routes this url for me.
How can I do additional coding under Joomla without being wiped out by Joomla update? Each time a joomla has an update, I have to add this code back mannually. But I have remember to do it.
I don't mind to do additional coding myself. But for this bug, I have to change Joomla core file. I don't believe this is right way to do it.
I'm not talking about a core hack. You can create a Plugin which then adds a rule to the router which parses the URL the way you are trying to modify it. That is update-safe.
You have lost a good Apache search engine friendly rewrite functionality. I reported this issue, but you refuse to accept responsibility. Instead you ask me to write my own plugin to get around your bug, which was already implemented by Apache. This is not acceptable attitude. Being a software developer myself since 1991, I have never seen any of my colleagues behave this way!
I had spent days and days to find out where the problem was and point out a good place for joomla developers to look at. You don’t realize this effort! Instead you trash my good damn effort.
How can you expect users to know how to write a joomla plugin? Do we have to be joomla system expert to use joomla?
In addition, joomla 3 fixed this exact same bug after I reported it a year ago.
You are asking us to change code so that we reintroduce a big again which is far bigger than your issue. Changing it the way you are asking would mean that Joomla again does not throw a proper 404 when the URL is faulty. So, again, no, we won't change this for all users out there, degrading performance for thousands of sites to accommodate your use case, which you could achieve with a plugin yourself.
I am not asking you to change in my way. I posted my code as a reference hoping you know where to look for. It is my fault to provide this reference.
I know my code is not the right fix. It has to be somewhere before calling that function.
This is originally an Apache feature, all I want is to give back that functionality. You feel like I ask for a new feature.
Bug reported several versions ago, but no fix has been made.
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39916.