Solved

.htaccess file redirect

Posted on 2014-09-24
11
272 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

773 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