This is a common problem, and there many common answers for this, but I have a specific small detail that does not work and reading documentation does not help me to understand the reason.
So, here is the problem: I want to remove www. from a domain name. I use .htaccess with mod_rewrite. Here is the code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.swedish\-cloud\.com$
RewriteRule ^(.*)$ "http\:\/\/swedish\-cloud\.com\/$1" [R=301,L]
It works, if I just type http://www.swedish-cloud.com. It changes it to http://swedish-cloud.com.
But if I type, for example: http://www.swedish-cloud.com/index.html, it does not change the URL to http://swedish-cloud.com/index.html
However, if I type a path to a non-existing file, like http://www.swedish-cloud.com/index2.html, it change the URL to http://swedish-cloud.com/index2.html showing a 404 Not Found error.
Can you please let me understand what I am missing? Thank you.
PS: I don’t have the root access to the server.
Let’s give you the correct answer. Your syntax for the cond is wrong but not significantly and the syntax for the rule is also wrong. Try:
Use an equality operator in the cond if that is want you want to do and then you don’t need to escape the match string.
The replacement string doesn’t need quotes or escapes and since you want the entire URI, why not just use $0 (the entire match pattern).