My url contains a broken link due to the http:// prefix not being added in places. How would I replace this using mod_rewrite:
http://website.com/www.websitelink.com
should go here:
http://www.websitelink.com
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In other words, if your path is /www.websitelink.com (
^is start of string,$is end of string; in regular expressions, dots are one-character wildcards and have to be escaped)(and
[NC]matching is not case sensitive – /WwW.webSiteLink.COM would match, too),[R=301]redirect with status “301 (Moved Permanently)”to http://www.websitelink.com/
and
[L]leave processing (no more rewrite rules are processed).Note that this will work regardless of the site’s domain (would work e.g. for http://website.com/www.websitelink.com and http://www.website.com/www.websitelink.com )
If you want to match all the paths that end with your domain, drop the starting
^:and if you want to match even paths without
www., make it optional:As @Litso noted, this won’t match the path after the “domain-in-path”; this should match the trailing path:
To match any subdomain:
And to match any domain: