2013-08-30 30 views
0

我有一个问题,谷歌索引了一些页面的URL错误。.htaccess从url中删除index.php和其他人

的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是不是我的专长,所以任何帮助,将不胜感激。

在此先感谢。

编辑:

  1. 好吧,我把它用两个方法,通过丹特林皮尔斯和Jon林工作。首先,我使用Dan Trimper方法生成mod重写url。例如http://www.mydomain.com/index.php?a=page&b=about,所以产生以后,会通过乔恩·林法产生的URL这样RewriteRule ^([^/]*)/([^/]*)$ /index.php?a=$1&b=$2 [L]

  2. 其次,生成我使用第二种方法重定向的URL http://www.mydomain.com/page/about后:

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

  3. 谢谢!

编辑2:没有工作,因为冲突。更准确的解决方案进入这个话题.htaccess friendly URl

+0

看看Mod重写http://httpd.apache.org/docs/current/mod/mod_rewrite.html – lampwins

回答

1

尝试在你的文档根目录添加这些规则,以你的htaccess文件:

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。

+0

谢谢。该网站转到正确的网址,但我得到404未找到。我需要像url重写或用户友好的网址。 RewriteEngine也打开模块。页面示例, Options + FollowSymLinks RewriteEngine On RewriteCond%{THE_REQUEST}^[AZ] {3,9} \ /index\.php\?a=page&b =([^& ] +) RewriteRule ^/page /%1? [R = 301,L] Napsters

+0

@napsters如果'http:// www.mydomain.com/profile/john'不存在,为什么在**世界**你会将google重定向到这些URL ? –

+0

我想修剪网址,就像是用漂亮的URLs使用htaccess文件。工作网址会像这样http:// www。mydomain.com/index.php?a=profile&u=john,并希望像上面的OP那样更改它。 – Napsters

1

当我第一次开始的时候,我对.htaccess也不是很了解。

看看这个网站以及.htaccess生成器 - 它帮助我了很多,我认为它会解决您的问题。

http://www.generateit.net/mod-rewrite/

它预先写入规则的配置之后 - 然后复制/粘贴到你的.htaccess文件。

+0

谢谢。我会尝试。 – Napsters