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

Related Articles

  1. Offer negotiation doesn
  2. 怎么样使用搜索引擎友好的URL链接?
  3. Windows 10下注册32位OCX控件的方法
  4. BT686 多媒体小电脑
  5. SSL Certificates and PCI Scanning
  6. 程序员
  7. 俄罗式方块 BASH
  8. DELPHI 动态数组小结
  9. 女程序员做了个梦,众网友的神回复
  10. Evernote 用户只用了 5%的功能,这着实给科技公司上了一课

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" />