Solved

.htaccess file redirect

Posted on 2014-09-24
11
274 Views
Last Modified: 2014-09-26
I'm trying to redirect visitors to our site to a new site unless they are looking for the CRM subdirectory.

So far I have
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/CRM [NC]
RewriteRule (.*) http://newsite.com/ [R=301,L]

Open in new window


But it is not redirecting anything.

Any ideas?
0
Comment
Question by:hrolsons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 15

Expert Comment

by:Insoftservice
ID: 40343466
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/CRM/
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

OR

RewriteEngine on
RewriteRule !^CRM($|/) http://example.com%{REQUEST_URI} [L,R=301]

OR

RewriteEngine On
RewriteCond %{REQUEST_URI} !/CRM
RewriteRule ^.*$ http://www.newsite.com/ [R=301]
0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 40344337
I like your original rule, with a minor edit:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/?CRM [NC]
RewriteRule /?(.*) http://newsite.com/$1 [R=301,L]

Open in new window

However, your existing rule should already be redirecting.  Make sure you have .htaccess files enabled, and troubleshoot their application if necessary.  If you can prove the .htaccess is being processed, try turning on the RewriteLog (instructions for 2.2 or 2.4).  Once you have the log reporting, paste the results of a single request which should have been directed, and we can assist.
0
 

Author Comment

by:hrolsons
ID: 40344674
Thank You "Steve Bink".  Through your link I was able to change httpd.conf and have "AllowOverride All".  Problem now is that it's not leaving the "CRM" directory alone.  When trying to access www.mysite.com/CRM I get an "Internal Server Error".
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 50

Expert Comment

by:Steve Bink
ID: 40344758
If you disable the Rewrite* set, do you still get the error?  If you disable the "AllowOverride" directive, do you still get the error?

You do not need to use "AllowOverride All" for the purposes of rewrite.   You only need the "FileInfo" group to allow rewrites to work.  It may be that allowing all overrides may be impacting other aspects of your CRM application.
0
 

Author Comment

by:hrolsons
ID: 40344786
I added this to httpd.conf and things seem to be working as expected now.  Hopefully I've not opened up a security hole.

<Directory "/usr/local/www/vhosts/mysite.com/html/CRM/">
    Options -Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Open in new window

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40344862
Glad you got it to work.  Is there is an .htaccess file inside the /CRM directory?
0
 

Author Comment

by:hrolsons
ID: 40344881
There is not.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40345010
Hrrmm...I'm curious what broke /CRM when you added the rule and AllowOverride.  In any case, it's working now, so probably best to adhere to the "not broken" principle.  :)

Good luck!
0
 

Author Comment

by:hrolsons
ID: 40345031
I was wrong.  There was an .htaccess file in there.  I forgot that I put one in a few weeks ago.
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 40345382
@hrolsons what was wrong in my answer.
Did you tried any of my answer
0
 

Author Comment

by:hrolsons
ID: 40346520
I'm sorry @insoftservice I did try your suggestions but due to the httpd.conf file it wasn't allowing the .htaccess file to execute no matter what was in there.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question