Search code examples
.htaccesshttp-redirecthttp-status-code-301

Domain name within domain name. How to redirect through htaccess


The crawling properties of site showing

  http://www.abc.com/http://www.abc.com/index.php?option=com_toys
  http://www.abc.com/http://www.abc.com/index.php?option=com_article
  http://www.abc.com/http://www.abc.com/index.php?option=com_play&view=category&vid=10

The site been crawled like this, with errors coming in as duplicate url. Correct url is

  http://www.abc.com/index.php?option=com_toys
  http://www.abc.com/index.php?option=com_article
  http://www.abc.com/index.php?option=com_play&view=category&vid=10

is there any way to 301 redirect i tried using

  RewriteCond %{REQUEST_URI} ^.*/http://www.abc.com.*$
  RewriteRule .*  index.php     [R=301,L]

But its not achieving the desired as redirecting to http://www.abc.com/index.php How to redirect through htaccess from incorrect url to correct url sttructure off site


Solution

  • Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+http://.+?(/index\.php\?[^\s]+) [NC]
    RewriteRule ^ %1 [R=301,L,NE]