Htaccess rewrite to remove url from path

.htaccessapache-2.2rewrite

Due to a previously misconfigured rewrite rule I have a whole lot of errors listed in webmaster tools like the following:-

http://www.domain.com/www.domain.com/page.html
http://www.domain.com/www.domain.com/page-two.html
http://www.domain.com/www.domain.com/another-page.html

This looked promising https://stackoverflow.com/questions/5976814/removing-string-from-url-using-htaccess but could not get it to work with the following:-

RewriteRule ^/www.domain.com/(.*)$ /$1 [R=301,L,QSA]

or

RewriteRule ^/www\.domain\.com/(.*)$ /$1 [R=301,L,QSA]

Best Answer

You have to put . (full stops) in square brackets like that [.] then it should work.

EDIT:

This should work: RewriteRule ^/www[.]domain[.]com/(.*)$ /$1 [R=301,L,QSA]

Full stops are now not treated as special characters.

Related Topic