Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to prevent site to be accessible by ip. It could be accessible by only domain name, so I tried with htaccess trick.

RewriteCond %{HTTP_HOST} !^mydomain\.com [NC]
RewriteRule .? http://mydomain.com%{REQUEST_URI} [R=301,L]

It did the trick now my siteurl is changed to mydomain.com instead of my ip. But as per my knowledge its not complete solution. Whenever I change permalinks new htaccess will be generated so above condition will be removed.

So I thought I have to try in index.php, tried to redirect if ip is there in url by following:

if(strpos($_SERVER['HTTP_HOST'],'111.111.111.11') !== false) {      
header("Location: mydomain.com".$_SERVER['REQUEST_URI']);
}

but it did nothing still site accessed by ip. Let me know if my approach is right or not. Suggest me anything else if there.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

WordPress does not create a complete new .htaccess. It just rebuilds the part between the WordPress markers:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Any rule placed outside of this block will not be touched.

share|improve this answer
    
Thanks @toscho.. Lack of knowledge.. –  Kamal Oct 30 '12 at 12:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.