homepage Welcome to WebmasterWorld Guest from 54.205.122.62
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Does the following work?
glimbeek



 
Msg#: 4181668 posted 8:05 am on Aug 4, 2010 (gmt 0)

I have a indexed test domain, which has duplicated content.

mydomain.com.testdomain.com/<a lot of pages>

and I want to redirect everything to:
www.mydomain.com/<a lot of pages>

so:
mydomain.com.testdomain.com/this/great/page/
to:
www.mydomain.com/this/great/page/

and
mydomain.com.testdomain.com/this/page/
to:
www.mydomain.com/this/page/
etc..

In addition I don't want to redirect the Google webmastertools file.

Will the following work?

RewriteCond %{HTTP_HOST} ^mydomain\.com\.testdomain\.com [NC]
RewriteCond $1 !^googlefile\.html$ [NC]
RewriteRule ^(.*)$ [mydomain.com...] [R=301,L]

With kind regards,

George

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4181668 posted 11:20 am on Aug 4, 2010 (gmt 0)

It should do.

glimbeek



 
Msg#: 4181668 posted 12:05 pm on Aug 4, 2010 (gmt 0)

Cheers for replying g1smd.

glimbeek



 
Msg#: 4181668 posted 2:31 pm on Aug 4, 2010 (gmt 0)

In addition.

The google file exists so the RewriteCond $1 !^googlefile\.html$ [NC] doesn't work AKA it is redirected as well when it shouldn't.

I tried adding the following 2 lines all the way at the top of my .htaccess file:

AcceptPathInfo Off
Options +FollowSymlinks -Indexes -MultiViews

so I'm left with:
AcceptPathInfo Off
Options +FollowSymlinks -Indexes -MultiViews
RewriteEngine on
DirectoryIndex index.php index.html

at the top of my htaccess file, but that doesn't seem to work either.

Am I forgetting something?

[edited by: glimbeek at 3:08 pm (utc) on Aug 4, 2010]

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4181668 posted 2:58 pm on Aug 4, 2010 (gmt 0)

It makes no difference to your code whether "googlefile.html" exists or not. A request for the URL-path /googlefile.html will NOT be redirected by this code.

Did you delete your browser cache before testing new server-side code? If not, your browser may show you stale cached server responses (like redirects) and file content.

Where is this code located? As written, it will work only in mydomain.com.testdomain.com/.htaccess

Do you have any other RewriteRule, Redirect, RedirectMatch, or Alias directives that could affect requests for the URL-path /googlefile.html?

Jim

glimbeek



 
Msg#: 4181668 posted 3:04 pm on Aug 4, 2010 (gmt 0)

Hi Jim,

I used several browsers and I cleared the cache.
mydomain.com.testdomain.com/.htaccess
is the same file as mydomain.com/.htaccess

different domains pointing to the same folder on my servers.

At the moment I start my htaccess file off with:

RewriteEngine on
DirectoryIndex index.php index.html

order allow,deny
<insert a few IP's here>

followed by:

RewriteCond %{HTTP_HOST} ^mydomain\.com\.testdomain\.com [NC]
RewriteCond $1 !^googlefile\.html$ [NC]
RewriteRule ^(.*)$ [mydomain.com...] [R=301,L]

Then a bunch of other code, all of which shouldn't as far as I can tell interfere with the above rule. Specially because the are placed below it in the .htaccess file?

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4181668 posted 3:43 pm on Aug 4, 2010 (gmt 0)

Understand that this rule won't run for /googlefile.html requests (unless you have mis-spelled something). As a result, the rules that follow this one *will* be processed for /googlefile.html requests.

So unless you have misspelled something, or unless there is another rule interfering with googlefile.html requests, then you have a complete mystery on your hands. Such magical mysteries don't really exist, so something else is wrong.

Be sure you *delete* your browser cache. Forcing a page reload does not always work. Again, look for other rules or directives that may be affecting /googlefile.html requests. You may wish to use the "Live HTTP Headers" add-on for Firefox (or something similar) to "watch" the client requests and server responses for /googlefile.html and be sure you have not got an unexpected redirect or redirect chain happening.

By the way, if "/googlefile.html" is your google WMT validation key, you may want to use the pattern "!^google[0-9a-f]{16}\.html" to accept any google validation key in this rule. I find this handy when the validation key changes, or when I have more than one for some reason.

But again, unless you've not spelled the actual name of "/googlefile.html" correctly, it won't be redirected by this rule, and the problem is elsewhere. If my assumption above is correct, then check especially for casing errors in your GWT validation file number's pattern. An uppercase letter in the pattern won't match a lowercase letter in the client request, and the result will be an unexpected/unwanted redirect.

Jim

zudorsoft

5+ Year Member



 
Msg#: 4181668 posted 3:29 pm on Aug 6, 2010 (gmt 0)

Hi guys,

I just run into this post and made a quick test - here is an example what is working for me on Apache2:

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com\.testdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/googlefile.html$ [NC]
RewriteRule ^(.*)$ [mydomain.com...] [R=301,L]


I would suggest to try this one.
Also I am not pretty sure what $1 refers to in your example; I think you just forgot the '/' before the file name and that caused all the problems.

glimbeek



 
Msg#: 4181668 posted 12:28 pm on Aug 23, 2010 (gmt 0)

To update the topic:

the above did work...
Thanks jsMorgan :)

I overlooked a rule interfered with what I wanted to do.

SO solved (:

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4181668 posted 1:49 pm on Aug 23, 2010 (gmt 0)

zudorsoft,

Your code and the previously-posted code are essentially identical. Your code checks %{REQUEST_URI} for a match with !^/googlefile\.html$, and the previously-posted code checks the value in $1 for a match with !^googlefile\.html$. The $1 is a back-reference to the local-URL-path captured by the pattern-match in the RewriteRule.

Because the RewriteRule pattern is always the first thing to be evaluated when processing a rule, these two methods will have identical results if the code is located in example.com/.htaccess

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved