2013-08-30 32 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