摆脱URL(Joomla 3.3/3.4/3.5)中的ID(类别和文章) [英] Get rid of ID (category and article) from URL (Joomla 3.3 / 3.4 / 3.5)
问题描述
我有一个仅按3个级别组织的Joomla 3.3.6
(已3.5.
)网站:
I have a Joomla 3.3.6
(edited: 3.5.
) site organized in only 3 levels:
- 四个大类别(i,ii,iii,iiii)
- 每一个都分为一些中间类别(A,B,C,...)
- 最后是文章
- 两种语言(en,pt)
设置Search Engine Friendly URLs
,Use URL rewriting
,Adds Suffix to URL
和multilanguage support
,的URL
应该的形式为
The URL
after setting Search Engine Friendly URLs
, Use URL rewriting
, Adds Suffix to URL
and multilanguage support
, should be in the form:
http://www.example.com/en/bigcatiii/intercatA/articlex.html
但是自Joomla-Baby-Version以来,有许多安装了Joomla并寻求解决方案的其他人,我得到了:
But as many others that have Joomla installed and ask for a solution since Joomla-Baby-Version, I got:
http://www.example.com/en/bigcatiii/666-intercatA/articlex.html
其中666是一个来自地狱的数字,它毫无目的地指示类别ID
where 666 is a number from hell indicating for no purpose a category ID
现在浏览答案,我找到了这个答案:
Now browsing for an answer, I found this answer:
Edit "components/com_content/router.php"
(You’ll probably have to re-do this step every time you update Joomla.)
Replace the lines 38 and 290 with:
$advanced = $params->get('sef_advanced_link', 1);
and Replace line 426 with
->where($db->quoteName(‘alias’) . ‘ = ‘ . $db->quote($segment));
首先,第426行已经和原始行中的一样.其次,这不能解决问题.它适用于:
Well, first of all, line 426 is already like that in the original. Second, this does not do the trick. It do works with:
http://www.example.com/en/bigcatiii/intercatA/articlex.html
但是,如果您浏览到以下网址,则会出现 404 错误:
But it breaks wit a 404 error if you browse to:
http://www.example.com/en/bigcatiii/intercatA.html
此外,我注意到 ID 号是不同的.虽然整个网址是
Also, I noticed that the ID numbers are different. While the whole URL is
http://www.example.com/en/bigcatiii/666-intercatA/articlex.html
同一类别的描述页面是
http://www.example.com/en/bigcatiii/333-intercatA.html
基于 .htaccess
RewriteEngine on
RewriteBase /
RewriteRule (\d+)-([^/]*) $2 [R=301,L]
URLs
似乎正常,但是找不到页面.如果我们可以提供使用 .htaccess 而不是更改Joomla核心的解决方案,那就更好了.
The URLs
appear ok, but the pages are not found. It would be so much better if we can provide a solution using .htaccess instead of changing Joomla core.
不过,如果其他Google推荐建议仍然有效,那么更改Joomla核心就可以了.
Still, changing the Joomla core would just fine, if this other googled suggestion was valid.
Copy "components/com_content/router.php" to "/templates/your-template/html"
这意味着,一旦将router.php
移至本地",则升级后无需重做所有内容. (除非,当然会更新router.php,以防您最好再次镜像它.)
Meaning that once you moved router.php
to your "local", you wouldn't need to redo all the stuff after an upgrade. (Unless, of course, router.php is updated, in case you would better mirror it again.)
感谢您的时间来解决这个难题!
Thanks for your time to solve this puzzle!
参考
编辑(2016年5月2日):Joomla的最新赏金最新版本3.5
Edited (2016/May/02): NEW Bounty for Joomla last version 3.5
推荐答案
我刚安装了一个joomla 3.5,旧的方法对我有效.由于路由器文件中的某些内容已修改,因此您必须在joomla升级后重复此过程.
I've just newly installed a joomla 3.5 and the old method works for me. Since something has been modified in the router file, you have to repeat the procedure after a joomla upgrade.
./components/com_content/router.php
中的行现在为34和295.
The lines are now 34 and 295 in ./components/com_content/router.php
.
再次将0
更改为1
,使其变为:
Again change the 0
into 1
so that it becomes:
$advanced = $params->get('sef_advanced_link', 1);
我的网址例如http://joomla.lan/en/category-en-gb/article-en-gb
启用Search Engine Friendly URLs
可以正常工作.
My URL is e.g. http://joomla.lan/en/category-en-gb/article-en-gb
works fine with Search Engine Friendly URLs
on.
在Adds Suffix to URL
切换为Yes
的情况下,会将.html
附加到URL.
Use URL Rewriting
和Unicode Aliases
可选工作.在IIS7或Apache上使用URL重写引擎时,必须将htaccess.txt
重命名为.htaccess
,将webconfig.txt
重命名为webconfig
.请注意,某些主机具有严格的服务器配置.如果得到500 internal server error
,则可能需要编辑.htaccess
,并通过添加前面的#
注释掉Options +FollowSymlinks
和/或Options -Indexes
和/或RewriteBase /
行.后者已在Joomla 3.5中停用.当将Joomla安装在子文件夹而不是Web根目录中时,RewriteBase
设置很有用.
With Adds Suffix to URL
switched to Yes
an .html
is appended to the URL.
Use URL Rewriting
and Unicode Aliases
work optionally. When using URL rewrite engine on IIS7 or Apache, you have to rename htaccess.txt
into .htaccess
and webconfig.txt
into webconfig
. Note that some hosters have a restrictive server configuration. If you get a 500 internal server error
, you might need to edit .htaccess
and comment out the lines Options +FollowSymlinks
and/or Options -Indexes
and/or RewriteBase /
by adding a preceding #
. The latter is already deactivated in Joomla 3.5. A RewriteBase
setting is useful when Joomla is installed in a subfolder, not the web root.
在其他服务器上,将Use URL Rewriting
设置为No
.
On other servers set Use URL Rewriting
to No
.
我无法重现您的问题,通过这两个代码编辑,一切正常.请再次尝试,如果无法解决,请发布确切的行为(网址,也出现错误). 如果无法修复它,则可能必须重新安装源代码.
I can't reproduce your problem, everything is working correct with those two code edits. Please try it out again and if you can't resolve, post the exact behavior (urls, errors aso.) If you can not get it fixed, you might have to reinstall the sources.
这篇关于摆脱URL(Joomla 3.3/3.4/3.5)中的ID(类别和文章)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!