我有一个 Joomla 3.3.6
(已编辑:3.5.
)网站仅分为 3 个级别:
- 四大类(i、ii、iii、iiii)
- 每个都分为一些中间类别(A、B、C、...)
- 最后是文章
- 两种语言(英文、英文)
设置Search Engine Friendly URLs
后的URL
,Use URL rewriting
,Adds Suffix to URL
and 多语言支持
,应该是这样的形式:
http://www.example.com/en/bigcatiii/intercatA/articlex.html
但自从 Joomla-Baby-Version 以来,许多其他安装了 Joomla 并要求解决方案的人,我得到了:
http://www.example.com/en/bigcatiii/666-intercatA/articlex.html
其中 666 是一个毫无意义的类别 ID
的数字现在浏览答案,我找到了这个答案:
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行在原文中已经是这样了。其次,这并不能解决问题。它适用于:
http://www.example.com/en/bigcatiii/intercatA/articlex.html
但如果您浏览到:
,它会中断404错误:http://www.example.com/en/bigcatiii/intercatA.html
另外,我注意到 ID 号码不同。虽然整个 URL 是
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]
URL
显示正常,但找不到页面。如果我们可以提供使用 .htaccess 而不是更改 Joomla 核心的解决方案,那就更好了。
不过,如果其他 google 搜索的建议有效的话,更改 Joomla 核心就好了。
Copy “components/com_content/router.php” to “/templates/your-template/html”
这意味着一旦您将 router.php
移动到您的“本地”,您就不需要在升级后重做所有的东西。 (当然,除非更新了 router.php,以防万一你最好再镜像一次。)
感谢您花时间来解决这个难题!
引用资料
1- Change/ Remove Article ID in URL?
2- Removing the Article ID number
3- How to remove article id in url?
4- Remove article id from url for joomla 3.0
6- Remove article id from joomla 3 URL
7- Remove article id from joomla 3 URL
编辑(2016 年 5 月 2 日):Joomla 最新版本 3.5 的新赏金
最佳答案
我刚刚安装了 joomla 3.5,旧方法对我有用。由于路由器文件中的某些内容已被修改,您必须在 joomla 升级后重复该过程。
./components/com_content/router.php
中的行现在是 34 和 295。
再次将 0
更改为 1
,使其变为:
$advanced = $params->get('sef_advanced_link', 1);
我的网址是http://joomla.lan/en/category-en-gb/article-en-gb
与 Search Engine Friendly URLs
配合使用效果很好。
随着 Adds Suffix to URL
切换到 Yes
一个 .html
被附加到 URL。
使用 URL 重写
和 Unicode 别名
可选。在 IIS7 或 Apache 上使用 URL 重写引擎时,您必须将 htaccess.txt
重命名为 .htaccess
并将 webconfig.txt
重命名为 webconfig
。请注意,某些托管商具有限制性服务器配置。如果您收到 500 内部服务器错误
,您可能需要编辑 .htaccess
并注释掉 Options +FollowSymlinks
和/或 Options -Indexes
和/或 RewriteBase/
通过添加前面的 #
。后者已在 Joomla 3.5 中停用。 RewriteBase
设置在 Joomla 安装在子文件夹而不是 Web 根目录中时很有用。
在其他服务器上将 Use URL Rewriting
设置为 No
。
我无法重现您的问题,这两个代码编辑后一切正常。请再试一次,如果您无法解决,请发布确切的行为(网址、错误等)。 如果无法修复它,您可能需要重新安装源。
关于php - 从 URL (Joomla 3.3/3.4/3.5) 中删除 ID(类别和文章),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26168517/