Whats wrong with htaccess redirect?

Avatar
  • Answered
I just signuped for this hosting, so I am new here.

I have another hosting account with Hostgator. On one of my sites over there I use next .htacces:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]


What it does is:

1) Forces all non-www requests to be redirected to www version of the url.

2) Second part of htaccess is to make pretty links without .php extensions.


When I place the code above in my .htaccess file, it redirects my to www.domain.com/%41 and shows redirect loop error.

Why it doesn't work here on inmotion hosting, yet work perfecly fine on my other hosting?

After I got that error I called the technical support and been told that my htaccess was incorrect and was suggested to use cPanel's redirect function.

I also tried to follow examples suggested here:

https://www.inmotionhosting.com/support/community-support/domain-names/how-do-i-force-the-www-version-of-my-website-using-the-htaccess-file

and here

https://www.inmotionhosting.com/support/community-support/cpanel/removing-file-extensions-in-htaccess

Neither of them worked...

Is there is anything I am not aware of about inmotion htaccess files handling?

I will not be able to use this hosting without getting these redirects to work properly.
Avatar
Scott
Hello CarlB,

Our servers are working fine with htaccess and these features you are working with are among the most common requests we have.

If you look at the .htaccess code, you will see that the $ characters were replaced by another, possibly by the editor that copied it was last edited by before it was copied into the server. I believe that is what is causing your issue.

I commented out your code and placed the proper code in. It is almost the same for the most part. This way you can see the differences. Feel free to remove the commented portion as you wish.

I tested the site and it is now redirecting to the www version and displaying your URLs without the php extension.

Best Regards,
Scott M