Solved

.htaccess file redirect

Posted on 2014-09-24
11
261 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
  • 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now