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

Related Articles

  1. Evernote 用户只用了 5%的功能,这着实给科技公司上了一课
  2. MySql
  3. 批量删除新浪微博的方法
  4. 哪些SEO方法会被搜索引擎认为是作弊
  5. Feeling down about your interviews/job search?
  6. Windows 10下注册32位OCX控件的方法
  7. SSL Certificates and PCI Scanning
  8. Getting a LOT of interviews
  9. This is hard for me too.
  10. RSS 订阅

Comments (0)

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">