页面顶部 Top
文件:  root - text - article - 2017 - 04 - site-news-user-friendly-urls-in-htaccess.txt
标签: SEO友好的链接设置, htaccess, mod_rewrite模块, APACHE2配置, user friendly URLs, mod_rewrite, apache2, htaccess, | 中文 | 主页 | 类别: 计算机科学 | 441 次阅读, 25769 次搜索 | 251 个汉字

定阅此目录的博客 | 浏览 | 博客存档
弄了一晚上 终于把本站所有的链接改成 SEO友好的了。

参数式的URL的坏处


原来就是比较恶心的 ?a=b&c=d&e=f 的形式。这种方式不会被搜索引擎认为是好的URL形式,参数关键字不会被采纳:如上面a, b, c 和 d 是都不会被索引的。别一坏处就是 URL变得过长,且不容易理解。

搜索引擎友好的URL


比如之前是 /?lang=ch&do=Welcome.Home
现在就变成 /ch/Welcome.Home
这样 ch 和 Welcome.Home 都能成为URL被索引关键字的一部分,而且更为容易理解,简短。

怎么样在Apache2 的 .htaccess 文件里设置?


主要针对 do, lang 和 rid 三个参数进行配置, 这样能满足大部分页面的需要. do 指定了一级页面, lang 指定语言, rid 指定了二级页面.


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?do=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|ch)/([^/]+)/?$ /index.php?do=$2&lang=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|ch)/([^/]+)/(.*)/?$ /index.php?do=$2&lang=$1&rid=$3 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.*)/?$ /index.php?do=$1&rid=$2 [L,QSA]


每一条 RewriteRule 前都得加上使用的前提条件就是 URL本身不是文件 或者文件夹。这样才能保证静态图片JS等资源不被地址重写。
还有就是要打开 apache2 的 mod_rewrite 模块。
标签: SEO友好的链接设置, htaccess, mod_rewrite模块, APACHE2配置, user friendly URLs, mod_rewrite, apache2, htaccess, | 中文 | 主页 | 类别: 计算机科学 | 441 次阅读, 25769 次搜索 | 251 个汉字 定阅此目录的博客

猜您喜欢...

  1. BT686 多媒体小电脑
  2. Evernote 用户只用了 5%的功能,这着实给科技公司上了一课
  3. 女程序员做了个梦,众网友的神回复
  4. Windows 10下注册32位OCX控件的方法
  5. 俄罗式方块 BASH
  6. 一个刚毕业的计算机相关专业学生,简历上有哪些经历会加分?
  7. 为什么不要在中国注册域名
  8. This is hard for me too.
  9. Offer negotiation doesn
  10. RSS 订阅

评论 (0)

    当前页暂时没有评论。


最后更新: October 30 2020 14:21:12 | RSS Subscription
牛排怎么做才好吃? | <meta name="机器人" content="不索引, 跟踪" />