【问题标题】:SEO friendly, non-www, hidden index.php URLSEO 友好,非 www,隐藏 index.php URL
【发布时间】:2013-05-09 10:26:21
【问题描述】:

我想用 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
    

我读过很多例子,但没有一个能正常工作。

编辑:

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

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

【问题讨论】:

  • 好吧,向我们展示您尝试过的和无效的。此外,您应该真正使用 php 路由器脚本进行 url 重写。它将使您的 apache 配置最小且干净,并且更易于维护。

标签: seo no-www


【解决方案1】:
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:

【讨论】:

    猜你喜欢
    • 2013-09-15
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 2011-05-29
    • 2011-01-22
    相关资源
    最近更新 更多