douhui5953 2012-07-04 13:13
浏览 62
已采纳

用.htaccess排除奇怪的页面

I have a strange situation occurring on my site where google thinks certain php pages are children of other php pages. For example, I am getting errors in Google Webmaster tools for pages showing up like: http://domain.com/page1.php/page5.php. Both page1.php and page5.php exist on the site, but I can't figure out why google thinks one should be concatenated to the other.

Browsing to such a link will load page1.php, but not correctly. My goal was to use .htaccess (or other suggestions) to simply redirect to the first page if additional pages follow. Am I thinking about this correctly, and can anyone offer suggestions to help me resolve this? Thanks!

Update: The only lines in my .htaccess file are redirecting from a previous folder structure to a single php file, but this has been in place for at least a year. For example:

RedirectMatch 301 ^/widgets/?$ http://firesage.com/widgets.php

Update2: I just found this 'Soft 404' error in Webmaster tools: http://domain.com/page2.php/include/include/lookup.php?id=22. First, I have the include folder excluded via robots.txt. And the fact that the include folder is listed twice in the url is very suspect.

  • 写回答

3条回答 默认 最新

  • douliang2167 2012-07-04 13:45
    关注

    Generally you can use .htaccess to redirect Google, but I would rather suggest you find the reason why Google sees those "wrong" links (s. Jeroen's comment to your question). Here's the .htaccess to start up with, until you've found the reason.

    <IfModule mod_rewrite.c>
    
    RewriteEngine On
    RewriteBase /
    Options +FollowSymLinks
    
    # every page on its own
    RewriteRule ^page1.php/(.*)$ /page1.php [R=301,L]
    RewriteRule ^page2.php/(.*)$ /page2.php [R=301,L]
    # or in general maybe the following to replace all of the above, if you think it'll fit
    # RewriteRule ^([^/.]+)\.php/(.*)$ /$1.php [R=301,L]
    
    </IfModule>
    

    Update
    If you also need to pass any possible GET parameters, just add the QSA flag so it becomes [R=301,L,QSA].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?