【发布时间】:2013-09-02 15:00:59
【问题描述】:
我有一个问题,谷歌索引了一些带有错误 url 的页面。
他们正在索引的网址是:
1. http://www.mydomain.com/index.php?a=profile&u=john
2. http://www.mydomain.com/index.php?a=page&b=about
3. http://www.mydomain.com/index.php?a=settings&b=avatar
4. http://www.mydomain.com/index.php?a=feed
5. http://www.mydomain.com/index.php?a=feed&filter=picture
6. http://www.mydomain.com/index.php?a=post&m=32
7. http://www.mydomain.com/index.php?lang=english
8. http://www.mydomain.com/index.php?a=messages&u=john&id=4
9. http://www.mydomain.com/index.php?a=feed&logout=1
我需要它重定向到:
1. http://www.mydomain.com/john or http://www.mydomain.com/profile/john
2. http://www.mydomain.com/about or http://www.mydomain.com/page/about
3. http://www.mydomain.com/settings/avatar
4. http://www.mydomain.com/feed
5. http://www.mydomain.com/feed/picture or http://www.mydomain.com/feed/filter/picture
6. http://www.mydomain.com/message/32
7. http://www.mydomain.com/lang/english
8. http://www.mydomain.com/messages/john
9. http://www.mydomain.com/logout or http://www.mydomain.com/feed/logout
.htaccess 不是我的强项,因此非常感谢任何帮助。
提前致谢。
编辑:
好的,我使用 Dan Trimper 和 Jon Lin 的两种方法让它工作了。首先,我使用 Dan Trimper 方法生成 mod rewrite url。比如
http://www.mydomain.com/index.php?a=page&b=about,所以生成后会产生像RewriteRule ^([^/]*)/([^/]*)$ /index.php?a=$1&b=$2 [L]这样的url-
其次,生成后我使用第二种方法将 url 重定向到
http://www.mydomain.com/page/about通过使用 Jon Lin 方法:RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php\?a=page&b=([^&\ ]+) 重写规则 ^ /page/%1? [L,R=301]
谢谢!
编辑 2:由于冲突,无法在上面工作。更准确的解决方案去这个话题.htaccess friendly URl
【问题讨论】: