dongzheng4556 2013-08-30 01:22
浏览 90

.htaccess从url中删除index.php和其他人

I have a problem whereby google has indexed some pages with the wrong url.

The url they are indexing is:

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

I need it to redirect to:

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 isn't my forte, so any help would be much appreciated.

Thanks in advance.

Edit:

  1. Ok, I got it working by using two method by Dan Trimper and Jon Lin. First I'm generate mod rewrite url by using Dan Trimper method. For example http://www.mydomain.com/index.php?a=page&b=about, so after generate it will produce the url like this RewriteRule ^([^/]*)/([^/]*)$ /index.php?a=$1&b=$2 [L]

  2. Second, after generate I'm using second method redirect url to http://www.mydomain.com/page/about by using Jon Lin method:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php\?a=page&b=([^&\ ]+) RewriteRule ^ /page/%1? [L,R=301]

  3. Thank you!

Edit 2: Not working above because conflict. More accurate solution goes to this topic .htaccess friendly URl

  • 写回答

2条回答 默认 最新

  • douchun1900 2013-08-30 01:31
    关注

    Try adding these rules to your htaccess file in your document root:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=profile&u=([^&\ ]+)
    RewriteRule ^ /profile/%1? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=page&b=([^&\ ]+)
    RewriteRule ^ /page/%1? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=settings&b=([^&\ ]+)
    RewriteRule ^ /settings/%1? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed&logout=1
    RewriteRule ^ /feed/logout? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed&filter=([^&\ ]+)
    RewriteRule ^ /feed/%1? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed
    RewriteRule ^ /feed/? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed&filter=([^&\ ]+)
    RewriteRule ^ /feed/%1? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=post&m=([^&\ ]+)
    RewriteRule ^ /message/%1? [L,R=301]
    

    etc.etc.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看