0

Am trying to do an IP and a URL canonicalization on my .htaccess for my website(www.mydomain.com.ng) and IP(http://173.254.30.129/) i did the below code but it did not work.

RewriteEngine On

Options -multiviews
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_HOST} !^www.mydomain.com.ng$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com.ng/$1 [L,R=301]
RewriteRule ^index$ index.php [NC,L]

I did the above code on my .htaccess and i visit my URL(mydomain.com.ng) it did not redirect to this (www.mydomain.com.ng).

RewriteEngine On
Options -multiviews
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_HOST} ^173\.254\.30\.129
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
RewriteRule ^index$ index.php [NC,L]

I did the above code on my .htaccess i visit this IP(http://173.254.30.129/) it does not redirect to this (www.mydomain.com.ng).

RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]

also i want to do the above code on my .htaccess but do not know want to test for if it work.

Please help me with this three issue with am trying to achieve in my .htaccess Thank you.

simon oni
  • 35
  • 6
  • Verify whether your `.htaccess` is enabled or not, by putting same garbage (random) text on top of your `.htaccess` and see if it generates 500 (internal server) error or not? – anubhava Jan 22 '15 at 15:10

1 Answers1

0

not sure if you still have this issue seeing as this question is over 6 months old, but here are the codes that work for me:

Redirecting the url:

RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Redirecting the IP address:

RewriteCond %{HTTP_HOST} ^XXX\.XXX\.XXX\.XXX
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

Your last piece of code is to avoid attacks by botnet scripts that automatically look for vulnerabilities in your software. They are sometimes identified as User-Agent libwww-perl, and that's why you are supposed to disallow access from User-agent Libwww-perl.

As to how to test that I'm not sure of unfortunately.

Ariella
  • 35
  • 4