user3803804
user3803804

Reputation: 3

Using .htaccess to fix multiple broken links in my site

I've recently bulk imported 14,000 items into a joomla K2 database and now realised the 'external URL' field required an http:// in front of the URL! So all the external links on my site are now going to http://www.example.com/www.externalurl.com instead of http://www.externalurl.com

I've worked out that I can probably use the .htaccess file to rewrite the incorrect URLs (which are going to a 404 error page at the moment) but I need a bit of help with the code for doing this.

If anyone can point me in the right direction that would be great - thanks.

Update from comment:

These suggestions unfortunately don't work - I think I should clarify my original question by saying I don't know what the "externalurl" is because it's different on various pages on the site. I think I need something like this:

RewriteRule ^/www\.([a-zA-Z0-9_-]+)$ www\.$1 [L]

i.e. rewrite www.mywebsite.com/www.externalurl.com to www.externalurl.com

I tried this and it's not having any effect though...

Hope you can help.

Upvotes: 0

Views: 440

Answers (2)

Stephen Ostermiller
Stephen Ostermiller

Reputation: 25494

You are trying to redirect them externally, then the redirect match would be:

RedirectMatch 301 ^/www\.externalurl\.com/?(.*) http://www.externalurl.com/$1 

Jon Lin's redirect match will redirect them back to your own site.

Upvotes: 0

Jon Lin
Jon Lin

Reputation: 143856

Try:

RedirectMatch 301 ^/www\.externalurl\.com/?(.*) /$1 

Upvotes: 1

Related Questions