Forum Moderators: phranque

Message Too Old, No Replies

Conditional rewrite problem

Conditional rewrite

         

pstone

5:52 pm on Jun 8, 2011 (gmt 0)

10+ Year Member



Here is an interesting case:
Google has indexed my test folder content and I am trying to convince it to recrawl the test folder I setup the redirection rules as follows:

RewriteBase /
RewriteRule ^test/(.*) [head-massage.net...] [R=301,L]

This works perfectly.

Now I would like to submit a sitemap.xml to google to make it more enticing for it to crawl the test folder and follow the redirection rules.
This brings two little problems, I need to redirect everything else but /test/sitemap.xml and I need to be exempted from the redirection so I can make administrative changes, like generating the sitemap.

Here is what I have done and it doesn't work:
RewriteBase /
# RewriteCond %{REQUEST_URI} !^test/sitemap.xml [NC]
RewriteCond %{REQUEST_URI} !test/sitemap.xml
RewriteCond %{REMOTE_HOST} !^111.111.111.*
RewriteRule ^test/(.*) [head-massage.net...] [R=301,L]

Whith the code above I am still redirected from my IP and the sitemap.xml is still redirected to the main site.

g1smd

11:59 pm on Jun 8, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Escape literal periods in patterns.

The code should be placed in the root .htaccess file for it to work (not in the test folder).

The trailing .* does nothing. Replace it with \. instead.

More importantly, your Sitemap should list only VALID URLs. It should not list URLs which redirect.

pstone

4:01 am on Jun 9, 2011 (gmt 0)

10+ Year Member



Thanks so much for helping.

More importantly, your Sitemap should list only VALID URLs. It should not list URLs which redirect.


OK, then my whole struggle is worth nothing. That was the reason I was trying to do that.
Can you explain why I shouldn't do that?

Oh and by the way, after a two weeks pause googlebot started to reindex a few pages per day since yesterday. I guess I won't be needing that anyway.

I hope that my indexed content from the test folder will get soon replaced by the root content, (identical).

As a matter of fact by removing the condition for the sitemap and keeping only condition for IP address will prevent future indexing of my test folder.

This could be a lesson for anyone else who is testing on the same server as the production server. (bad idea, but if your budget is limited this could work.

g1smd

7:19 am on Jun 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can you explain why I shouldn't do that?

Google says "Sitemap must list ONLY valid URLs; not redirects or 404s".


Protect your dev folder with .htpasswd and you'll never have this problem again.

pstone

1:12 pm on Jun 9, 2011 (gmt 0)

10+ Year Member



Super,
Thanks so much for your help.