Forum Moderators: phranque
I've found more than one remote link using "ww" or "wwww" insead of "www"
I'd like to write one rule to deal with this. Would something like this work to effectively deal will these types of mistakes?
RedirectMatch 301 ^my_domain [my_domain.com...]
Thanks
RedirectMatch 301 ^my_domain(.*)$ [my_domain.com...]
will correct links to the site's inner pages as well.
The various Redirect directives all require a local path on the left side, and so are not aware of the requested domain. I'd recommend using mod_rewrite to solve this problem.
As long as these requests actually arrive at your server, we can probably use the ever-popular "not the right subdomain" rewrite to do this. However, if the "wwww." and "ww." requests are not mapped to your server by DNS, then we can't do anything about it in .htaccess; this would have to be handled in your DNS set-up first (using "wild-card" DNS).
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
ReewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(ww¦wwww)\.mydomain\.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(w{1,2}¦w{4,})\.mydomain\.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
As long as these requests actually arrive at your server, we can probably use the ever-popular "not the right subdomain" rewrite to do this.
Thanks Dave, Jim. Yes, the requests are answered by my server and the pages are displayed regardless, however with my anti-image-leeching code, the pages fall victim to my own safeguards. Rather than continue to add numerous mispelled domains to my rewrite, I'm seeking to do it with one rule. I use no subdomains, so I'm understanding you to say that this should work to change the typos to the correct URL:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.mydomain\.com
ReewriteRule ^(.*)$ [mydomain.com...] [R=301,L]
<added>
That didn't work - it shut down the site, producing a "processing error" page from the server. I had changed the "ReewriteRule" to "RewriteRule" assuming the extra "e" was itself a typo.
<added><added>
This was the error in the logs:
[Sat Aug 2 12:21:07 2003] [alert] [client 212.181.174.220] /www/m/my_account/htdocs/.htaccess: RewriteCond: bad argument line '%{HTTP_HOST}!^www\.my_domain\.com'
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
Dave,
The RedirectMatch doc says it matches the supplied regex against the requested URL-path, so I assumed that this was a local path specification, just like that used in Redirect, but in regex format. I've never tried to use a full URL in RedirectMatch myself - does it work?
Jim
I do recall a LONG time back, when the board was much smaller and, collectively, we were not so experienced, that RedirectMatch was commonly used and suggested to members.
Yes, no doubt you can place a full URL on the right side as a "target" URL and redirect to a different domain based on matching all or part of the REQUEST_URI, but the question is whether a hostname can appear in the pattern on the left side and be tested against the current HTTP_HOST variable in order to enable or disable the redirect taking place.
Now I'm gonna have to root around and see if I still have access to a site where I have not already implemented alternate-domain-name redirection so that I can test this! Can't stand not knowing... :)
Jim