Welcome to WebmasterWorld Guest from 54.167.86.211

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

rewrite everything except a single url

     
12:40 pm on May 20, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 18, 2010
posts: 127
votes: 0


I'm doing the following:

RewriteCond %{HTTP_HOST} ^www.exam-ple.com [OR]
RewriteCond %{HTTP_HOST} ^exam-ple.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Which works fine.

Now I want to exclude a single file for both options:

RewriteCond %{HTTP_HOST} ^www.exam-ple.com [OR]
RewriteCond %{HTTP_HOST} ^exam-ple.com
RewriteCond %{REQUEST_URI} !^/thefile\.html$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]


but going to [()exam-ple.com...] still gets redirected to: http://www.example.com/thefile.html

What am doing wrong?
1:51 pm on May 20, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 18, 2010
posts: 127
votes: 0


Note:

The file I DO NOT want to redirect is a google verification file, for instance:
google1aad878a5v471m44.html

Using the following code works:
RewriteCond %{HTTP_HOST} ^www.exam-ple.com [OR]
RewriteCond %{HTTP_HOST} ^exam-ple.com
RewriteCond %{REQUEST_URI} !^/thefile/$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

But that's for a folder not for a file... more specifically the Google verification file (:

Creating it for a file, using:

RewriteCond %{REQUEST_URI} !^/testt\.html$ [NC]

Works as well...

So why doesn't it work for the Google verification file?
1:58 pm on May 20, 2010 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


Your code can be simplified and improved, but it should have worked... Did you delete your browser cache before testing?

RewriteCond %{HTTP_HOST} ^(www\.)?exam-ple\.com [NC]
RewriteCond $1 !^excluded-file\.html$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Jim
2:02 pm on May 20, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 18, 2010
posts:127
votes: 0


Well the code works if I don't use the full file name:

google1aad878a5v471m4.html instead off
google1aad878a5v471m44.html

To explain things further:

the new domain is on the same ftp but in a subfolder
so google1aad878a5v471m44.html is also in the subfolder
so you have
/google1aad878a5v471m44.html (which does not need a redirect)
and
/example-folder/google1aad878a5v471m44.html

All the other pages get redirect to new domain aka the /example-folder/.

Could that be the issue?
2:05 pm on May 20, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 18, 2010
posts:127
votes: 0


I test in 5 different browsers across 2 pc's when I get this confused.

I tested your code but that also redirects to the new domain where the file is also located.

google1aad878a5v471m44.html was the file

google1aad878a5v471m.html gets redirecten as well now?
2:27 pm on May 20, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 18, 2010
posts:127
votes: 0


Did some more testing and it really looks like the cause for the file ALWAYS redirecting is the fact that the same file can be found in the subfolder. The subfolder in which the files for the new domain are located. Is there a way to work around this?
2:37 pm on May 20, 2010 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


Disable MultiViews and AcceptPathInfo if you are not using them. Example:

AcceptPathInfo Off
Options +FollowSymLinks -Indexes -MultiViews

AcceptPathInfo is available only on Apache 2.x servers. You'll get an error trying to enable or disable in on Apache 1.3x.

Jim
3:42 pm on May 20, 2010 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


Just a note on the google verification files...
Just in case you may have to get a new verification code in the future, you can exclude all valid google verification file requests in the top-level directory using

RewriteCond $1 !^(google|noexist_)[0-9a-f]{16}\.html$

Note that the "noexist_" request is how google tests your 404 response, and you certainly don't want to mess that up with a redirect...

Jim
6:49 am on May 21, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 18, 2010
posts: 127
votes: 0


Thanks for the reply jdMorgan,

AcceptPathInfo Off
Options +FollowSymLinks -Indexes -MultiViews

These are all kind off new to me.

At the moment I start my .htaccess file with:
Options +FollowSymlinks
RewriteEngine on

What does AcceptPathInfo Off do?
And what does -Indexes -MultiViews do?
Do I need to make sure I don't do anything else that might interfere with these new additions?
6:50 am on May 21, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 18, 2010
posts: 127
votes: 0


It's weird though...

Did a quick test

and if I upload thefile.html to both location and add a rule for thefile.html so it doesn't get redirected it works? As in it doesn't get redirected.

So why does it work for thefile.html

but not for my google verification file?

Ps.

I'm working with the following:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.exam-ple.com [OR]
RewriteCond %{HTTP_HOST} ^exam-ple.com
RewriteCond %{REQUEST_URI} !^/thefile\.html$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Even though the code could be "simplified and improved", I know what this does so I want to get it to work with this and then switch to your suggestion after I figured out what causes the weird behaviour.
3:09 pm on May 21, 2010 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


Please take the initiative -- I have very limited time to volunteer here repeating well-documented information, or to spend trying to convince you to test my recommendations. (Thanks)

What does AcceptPathInfo Off do? [httpd.apache.org]
And what does -Indexes -MultiViews do? [httpd.apache.org]

Jim
6:09 am on May 25, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 18, 2010
posts: 127
votes: 0


Thanks for the reply jdMorgan!

I understand you have very limited time and I appreciate your support. I read both pages before asking, but I didn't fully understand.

I will try your recommendations and see how I do.

George
7:19 am on May 25, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 18, 2010
posts: 127
votes: 0


That's odd, I replied but nothing showed up?

Anyway, I tried your solution and it works.

Thanks for the great support Jim. I'm still not a 100% how your solution works though.

George
3:07 pm on May 25, 2010 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


Read the documentation on MultiViews (mod_negotiation) and AcceptPathInfo (core). They do somewhat-different things but in both cases, the key idea is that each function acts if the requested URL-path does not resolve to an existing file.

Either of them can pre-empt mod_rewrite, causing a rewriterule to appear to fail. In fact, the problem is not that the rule is failing, but rather that the rewriterule is never applied if MultiViews or AcceptPathInfo runs first.

When you said that your code worked if the file existed, that indicated to me that the likely problem was the action of MultiViews and/or AcceptPathInfo.

Glad you got it working!

Jim
6:48 am on May 26, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 18, 2010
posts:127
votes: 0


Thanks again for the support and explaining it to me.

Regards,

George
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members