Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

.htaccess file redirect

Posted on 2014-09-24
11
Medium Priority
?
281 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 51

Accepted Solution

by:
Steve Bink earned 2000 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
Independent Software Vendors: 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!

 
LVL 51

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 51

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 51

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

916 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