Solved

.Htaccess on web server not working?!

Posted on 2013-10-28
9
635 Views
Last Modified: 2013-10-30
hi guys,

we're trying to get .htaccess to work and it isn't on our Amazon EC2 instance. Our developer has put the following code into the .htaccess file:

RewriteEngine on

# perform redirect if
RewriteCond %{HTTP_HOST} ^externalip$ [NC]
RewriteRule ^(.*)$ http://www.google.co.uk [R=301,L]

(i've deliberately hidden the external ip by commenting it above).

So when we go to the external IP address, it doesn't redirect to www.google.co.uk.

It's so important we get this working.

Any ideas guys?

Thank you
Yashy
0
Comment
Question by:Yashy
  • 4
  • 4
9 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
In PHP you can test $_SERVER['HTTP_HOST'] and redirect with header().  Since we can't see the true URL because you have hidden it (why?) we can't tell if there is a case-sensitivity issue, etc.
0
 
LVL 1

Author Comment

by:Yashy
Comment Utility
thank you sir. This is the IP 54.229.59.230. Should I change the .htaccess file from what it is right now?
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
Comment Utility
It looks like it rewrites to /home.  Are you sure you have the right version of .htaccess (maybe a different directory?)
0
 
LVL 1

Author Comment

by:Yashy
Comment Utility
The .htaccess file which the modification has been made to is in the /var/www/html/ directory.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
0
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 300 total points
Comment Utility
Is that the ONLY content in the .htaccess file? Are there any other .htaccess files, or any other configuration lines containing the word "redirect" or "home" ?

1. Usually if an .htaccess file has incorrect instructions, you'll get an HTTP 500 error.

2. If the AllowOverride isn't turned on for your host, then the .htaccess file will get ignored.

3. When using name-based virtual hosts (where one IP address can be used for multiple domain names / virtual hosts), going to the IP address will go to the FIRST virtual host entry in your Apache configuration that uses that IP address. So it's possible that Apache is sending the user to one virtual host and you're putting your .htaccess file in a different one.
0
 
LVL 1

Author Comment

by:Yashy
Comment Utility
thanks for all your help here.

How can I find if there's more than one .htaccess file via the command?

I have set the 'AllowOverride None' to 'AlloverOverride All'.

Also, I am unaware of any other config files have the word 'redirect' or 'home', but again....how would I find those?
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
How can I find if there's more than one .htaccess file?
Look in the directory listings.  It always has the same name.
0
 
LVL 1

Author Comment

by:Yashy
Comment Utility
Guys, we worked it out.

The actual .htaccess was being completely overlooked as we weren't even getting a 500 error.

So we looked at the httpd file and in there, our developer went into the conf.d folder and there's a php.conf file which he opened and made changes to. It's now working as it should be.

Guys, thank you so much for all your input. It led us to the conclusion that htaccess is being overlooked.

Thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 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

15 Experts available now in Live!

Get 1:1 Help Now