• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

Apache Rewrite or Redirect to Send Requests Made to IP to the Hostname

I'm trying to configure apache to where if the client makes a request to my IP address they are redirected to my hostname and away from the IP. This is what I've tried that doesn't work:

  RewriteEngine on
  RewriteRule ^my.ip.here/(.*) http://www.myurl.com/ [L,R=301]

What's the best practice to achieve what I'm trying to do?

1 Solution
Steve BinkCommented:
What you want is here:


Specifically, the HTTP_HOST variable:

RewriteCond %{HTTP_HOST} !^www.myurl.com$
RewriteRule /?(.+) http://www.myurl.com/$1 [R]
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now