搜索引擎友好(SEF)、可读的url是对人和搜索引擎都有意义的url,因为它们解释了它们所指向的特定页面的路径。从1.5版开始,Joomla!能够以任何格式创建和解析url,包括SEF url。这并不依赖于由web服务器执行的URL重写,所以即使Joomla!使用mod_rewrite模块运行Apache以外的服务器。SEF URL遵循特定的固定模式,但用户可以为URL的每个片段定义一个简短的描述性文本(别名)。
Internally, the local part of a SEF URL (the part after the domain name) is called a route. Creating and processing SEF URLs is therefore referred to as routing, and the relevant code is called a router.
The procedure for enabling Search Engine Friendly URLs differs depending on the web server you are using. If you are using shared hosting, it is probably Apache. Ask your hosting provider for more information if you are uncertain.
Only the most popular web servers have been included on this page.
在内部,SEF URL的本地部分(域名后面的部分)称为路由。因此,创建和处理SEF url被称为路由,相关的代码被称为路由器。
启用搜索引擎友好url的过程因使用的web服务器不同而不同。如果您使用的是共享主机,则可能是Apache。如果您不确定,请向您的主机提供商询问更多信息。
下面简要介绍Apache服务器的配置方法:
Apache
验证.htaccess已启用
Check that your Apache config file allows .htaccess overrides. You must make sure overrides are enabled or the .htaccess file in your Joomla! root directory will be ignored or cause an error. In the <Directory> section of your virtual host configuration file or in the main (httpd.conf
) configuration file you must have something similar to the example below enabling overrides:
检查你的Apache配置文件是否允许.htaccess文件进行重载。你必须确保重载允许或者你的Joomla!根目录将被忽略或导致错误。在你的虚拟主机配置文件的<Directory>部分或在主(httpd.conf)配置文件中,你必须有类似下面的例子启用重载:
<Directory "/home/user/public_html">
AllowOverride All
</Directory>
<Directory "/path/to/htdocs">
AllowOverride All Options=[an option],[an option],...
</Directory>
如果你不能访问你的站点的配置文件,还有其他的方法来测试. 请访问更多相关信息 -- .htaccess tutorial found on The Apache Software Foundation 。
配置步骤
以下是配置步骤. 请按照它们在这里展示的顺序进行配置,如果一个步骤失败了,不要继续,直到你解决每步的问题。
- 在joomla跟目录, 重命名文件
"htaccess.txt"
为".htaccess"
. - 这个步骤可能不是必需的。在文本编辑器中打开。htaccess。取消注释RewriteBase /(删除第一个字符#)。如果Joomla安装在它自己的文件夹中,请在正斜杠后输入Joomla文件夹名称。例如RewriteBase / yourjoomlafolder。
- 登录到后端并打开全局配置。
- 启用使用Apache mod_rewrite/URL重写选项和保存。这个选项使用Apache mod_rewrite函数来消除URL中的"index.php"部分。
-
检查您的网站是否工作正常。你的url现在应该是这样的:
http://www.example.com/the--news/1--latest--news/1--welcome--to--joomla
- 如果没有启用,并且您可以访问apache/conf/httpd.conf文件,打开该文件,检查是否有LoadModule rewrite_module modules/mod_rewrite. conf行。注释也是如此。如果有必要,取消注释该行并重新启动Apache web服务器。
- 如果mod_rewrite无法启用,请关闭此选项。如果你将。htaccess文件重命名也没有关系。
-
- 如果您认为这是必要的,启用添加后缀到url和保存。该选项将.html添加到url的末尾。对于这是否有必要甚至有用,人们有不同的看法。搜索引擎似乎并不关心你的url是否以.html结尾。
- 打开插件管理器并启用System - SEF插件。这个插件为Joomla文章中的链接添加了SEF支持。它直接在HTML上操作,不需要特殊的标记。