SEO友好,非www,隐藏index.php URL

时间:2013-05-09 10:26:21

标签: seo no-www

我想用apache mod_rewrite做四件事:

  1. 删除www

    http://www.example.com/ >>> http://example.com/
    
  2. 删除index.php

    http://example.com/index.php >>> http://example.com/
    
  3. 重写URI

    http://example.com/index.php?rewrite=request >>> http://example.com/request
    
  4. 删除最后一个斜杠

    http://example.com/request/ >>> http://example.com/request
    
  5. 我已经阅读了很多例子,但没有一个能够正常运作。

    修改

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^example\.com
    RewriteRule (.*) http://example.com/$1 [R=301,L]
    
    RewriteRule ^([^/\.]+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
    RewriteRule ^([^/\.]+)$ index.php?rewrite=$1 [L]
    </IfModule>
    

    我现在正在使用它,但这还不够。感谢

1 个答案:

答案 0 :(得分:0)

RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*)http://www.example.com/$1 [R=301,L]


RewriteRule ^([^/\.]+)/$ http:// %{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^([^/\.]+)$ index.php?rewrite=$1 [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ index\.php\ HTTP
RewriteRule ^index\.php$ http:// www.example.com/ [R=301,L]

使用apache mod_rewrite: