LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-18-2015, 02:33 AM   #1
kenweill
LQ Newbie
 
Registered: Jan 2007
Location: Philippines
Distribution: Linux Mint 17 Cinnamon 64bit
Posts: 12

Rep: Reputation: 0
How can I .htaccess 301 redirect all pages/files (EXCEPT FOR ONE) to new domain?


How can I .htaccess 301 redirect all pages/files (EXCEPT FOR ONE) to new domain?

I have already made an .htaccess file that successfully redirects most all the different pages and files on my old domain (www.olddomain.com) to my new domain (www.newdomain.com).

HOWEVER, I need one page to NOT be redirected to the new site, that page is the google verification .html file:
Code:
http://www.olddomain.com/googleverification.html
.

I have attached the most relevant parts of the file are pasted below:

---------RELEVANT PARTS OF THE .HTACCESS FILE---------
Code:
RewriteEngine On

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

RewriteCond %{REQUEST_URI}  !\.(php|html?|jpg|gif|png|pdf|tiff|bmp|ico|gz|zip|xml|txt)$
RewriteRule ^(.*)([^/])$ http://www.newdomain.com/$1$2/ [L,R=301]


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Last edited by kenweill; 06-18-2015 at 02:34 AM.
 
Old 06-18-2015, 04:03 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

You can use:
Code:
RewriteCond %{HTTP_HOST} !^www.newdomain.com$
RewriteCond %{REQUEST_URI} !^/googleverification.html
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
 
1 members found this post helpful.
Old 06-18-2015, 04:19 AM   #3
kenweill
LQ Newbie
 
Registered: Jan 2007
Location: Philippines
Distribution: Linux Mint 17 Cinnamon 64bit
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bathory View Post
Hi,

You can use:
Code:
RewriteCond {HTTP_HOST} !^www.newdomain.com$
RewriteCond %{REQUEST_URI} !^/googleverification.html
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
It now works. After removing my first rule. It must have conflicted with my other redirections.
Thanks.

Last edited by kenweill; 06-18-2015 at 07:52 AM.
 
Old 06-18-2015, 05:55 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Originally Posted by kenweill View Post
Thanks. But I tried this and it has no effect.
Are you sure apache reads the .htaccess file in question
And I guess you have cleared your browser cache before testing
 
1 members found this post helpful.
Old 06-18-2015, 07:10 AM   #5
kenweill
LQ Newbie
 
Registered: Jan 2007
Location: Philippines
Distribution: Linux Mint 17 Cinnamon 64bit
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bathory View Post
Are you sure apache reads the .htaccess file in question
And I guess you have cleared your browser cache before testing
Okay. I cleared the cache and reload and I got redirected to
Code:
http://www.newdomain.com/googleverification.html
instead of
Code:
http://www.olddomain.com/googleverification.html
 
Old 06-18-2015, 07:40 AM   #6
kenweill
LQ Newbie
 
Registered: Jan 2007
Location: Philippines
Distribution: Linux Mint 17 Cinnamon 64bit
Posts: 12

Original Poster
Rep: Reputation: 0
I found a solution and it works.

Code:
RewriteEngine On

RewriteCond {HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{THE_REQUEST} !/googleverification\.html [NC]
RewriteRule ^ http://www.newdomain.com%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_URI}  !\.(php|html?|jpg|gif|png|pdf|tiff|bmp|ico|gz|zip|xml|txt)$
RewriteRule ^(.*)([^/])$ http://www.newdomain.com/$1$2/ [L,R=301]


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
I also tried your code again, but this time, removing the first rule on my original codes and it also works.
I guess it conflicted with my other redirection that's why on my first test, it didn't work.

Thanks.

Last edited by kenweill; 06-18-2015 at 07:51 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
301 Redirect Dynamic Index.php Only dtown411 Linux - Server 3 09-08-2013 01:58 AM
[SOLVED] Creating 301 Permanent Redirect to a domain with same docroot as old domain. MarkToronto Linux - Newbie 1 05-15-2013 03:35 AM
301 redirect not working after setting up .htaccess file jprine Linux - Newbie 1 09-23-2011 04:03 PM
htaccess 301 rewrite BillKat Linux - Server 2 04-07-2009 12:54 PM
cannot get 301 redirect to function geoman Linux - General 4 01-17-2006 08:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration