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 | 461 Views, 26205 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 | 461 Views, 26205 Search Bots | 251 Characters Subscribe to Feed Burner

Related Articles

  1. MySql
  2. Getting a LOT of interviews
  3. 儿童编程热和计算机思维的培养
  4. Windows 10下注册32位OCX控件的方法
  5. 女程序员做了个梦,众网友的神回复
  6. BT686 多媒体小电脑
  7. 传RSA加密系统已被密码学大牛破解
  8. 哪些SEO方法会被搜索引擎认为是作弊
  9. 微信拉黑和删除有啥区别?
  10. Offer negotiation doesn

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="index, follow">