To the Top
File:  root - text - article - 2017 - 04 - site-news-user-friendly-urls-in-htaccess.txt
Tags: SEO友好的链接设置, htaccess, mod_rewrite模块, APACHE2配置, user friendly URLs, mod_rewrite, apache2, htaccess, | 中文 | Home Page | Category: Computing | 465 Views, 26458 Search Bots | 251 Characters

Subscribe to Feed Burner | Browse | Archive
弄了一晚上 终于把本站所有的链接改成 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 模块。
Tags: SEO友好的链接设置, htaccess, mod_rewrite模块, APACHE2配置, user friendly URLs, mod_rewrite, apache2, htaccess, | 中文 | Home Page | Cateogry: Computing | 465 Views, 26458 Search Bots | 251 Characters Subscribe to Feed Burner

Related Articles

  1. 为什么不能在中国设立第十四个根域名服务器
  2. MySql
  3. 腾讯,从公敌到大哥
  4. This is hard for me too.
  5. 怎么样使用搜索引擎友好的URL链接?
  6. 哪些SEO方法会被搜索引擎认为是作弊
  7. RSS 订阅
  8. AlphaGo第97手失误,李世石为人类赢下荣誉之战
  9. Windows 10下注册32位OCX控件的方法
  10. 一个刚毕业的计算机相关专业学生,简历上有哪些经历会加分?

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />