htaccess redirect


DougF

Recommended Posts

I need help creating an htaccess redirect from

http://www.example.com/http://www.example.com/sitemap.xml
to
http://www.example.com/sitemap.xml

Yes, the duplicate domain name is intentional. An incorrect file name was entered for Google analytics sitemap and the beast keeps searching for this file even though the file name was corrected long ago.

Tried the following but can't get it to work:

RewriteRule /http://www.example.com/sitemap.xml http://www.example.com/sitemap.xml [R=301,L]

Apache seems to strip the duplicate domain name from the redirect and then throws a loop error. Any ideas how it can be forced to view the duplicate domain name as part of the path?

Thanks

Link to comment
Share on other sites

I think this might work


RewriteRule ^/http://www.example.com/sitemap.xml$ http://www.example.com/sitemap.xml [R=301,L]

Thanks Tony,

Tried that one but Apache's default behavior is to strip out the domain from the path. This removes the duplicate domain name and then throws infinite loop error because the redirect is on the same file name. There must be a command to force Apache to use the path as provided. I'm reading through Apache doc's but they are not exactly user friendly...

Link to comment
Share on other sites

Thanks Tony,

Tried that one but Apache's default behavior is to strip out the domain from the path. This removes the duplicate domain name and then throws infinite loop error because the redirect is on the same file name. There must be a command to force Apache to use the path as provided. I'm reading through Apache doc's but they are not exactly user friendly...

Can you make a support ticket and ask for it to be flagged for Tony? I'm pretty sure I can figure it out but it be best if I was actually doing it on your site rather than trying to do it from a test system.

Link to comment
Share on other sites

Solved by Tony.

Thought I'd post for future reference.

Rather than fighting with Apache just create what Google is looking for and then create redirect that Apache likes...

1) Create bogus folder that Google is searching for:

/home/~example/public_html/http:/www.example.com/

2)create a 301 redirect htaccess in bogus folder:

RewriteEngine On

RewriteRule ^(.*)$ http://www.example.com/sitemap.xml [R=permanent,L]

Link to comment
Share on other sites

I just thought about this and maybe we were close and the issue was just one thing. Since the directory was actually http:/ rather than http:// makes me wonder if maybe the rewrite should have been this:

RewriteRule ^/http:/www.example.com/sitemap.xml$ http://www.example.com/sitemap.xml [R=301,L]

So one less / for the http:// portion. Although might be wrong there as well. Oh and also might be : is a rewrite char as well might need to be a : as well? I'm really not sure there are a lot of things I want to question on the original attempt. These days I don't bother with rewrites most stuff you're sending it in via just one rule and a routing system handles the rest IE: Zend Framework. So maybe just missing something very obvious here.

Link to comment
Share on other sites

Usually these redirect challenges are always just "one thing" away from success...

Originally I tried escaping the colon after http but made no difference. Never though of the double backslash. At this point your solution is catching what Google is looking for so I'm happy. It is such an easy error to make I wonder why Google does not check and strip off domain from form entry on their analytics site.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...