0

I'm trying to redirect http://www.example.me to http://example.me, but for some reason it's not working. Can somebody help me with this by telling what is wrong on my .htaccess file?

<IfModule mod_rewrite.c>

RewriteEngine On

SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots

RewriteCond %{HTTP_USER_AGENT} libwww [NC,OR]

RewriteCond %{QUERY_STRING} ^(.*)=http [NC]

RewriteRule ^(.*)$ – [F,L]

RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^/?$ "http\:\/\/example\.me\/“ [R=301,L]

# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0

# Set up caching on media files for 1 month
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A2419200
Header append Cache-Control "public"
</FilesMatch>

# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>

# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive On
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>

</IfModule>
MrWhite
  • 43,179
  • 8
  • 60
  • 84
Marcell Almeida
  • 292
  • 3
  • 9
  • Double quotes per se aren't a problem, however, you seem to have an odd "curly quote" (`“` as opposed to `"`) at the end of your `RewriteRule` substitution - this would cause a problem, as _any_ stray character would. – MrWhite Oct 29 '15 at 15:56

2 Answers2

0

Try this and also do not use quotes in your rule

RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^ http:\\example.me [R=301,L]
Panama Jack
  • 24,158
  • 10
  • 63
  • 95
  • It also worked. I discovered that the problem with my file was the quotes and I've fixed. But why do you recommend to not use quotes on my rule? – Marcell Almeida Apr 21 '15 at 20:15
  • Because you don't need quotes there. If you didn't have them you wouldn't have had that problem to begin with. Save yourself the issue and don't use them unnecessarily. Also if someone takes the time to answer your question and helped you solve it `you shouldn't answer your own question`. People will be less likely to help you in the future. :) – Panama Jack Apr 21 '15 at 20:53
  • I see your point, Panama Jack. I really don't need them. Just removed from my .htaccess. Regarding answering my own question, I did it before seeing your answer, sorry about that. Thanks for your help :) – Marcell Almeida Apr 23 '15 at 00:15
0

It was a problem with the quotes. Below is the correct .htaccess

The error was on this line with the last quote

RewriteRule ^/?$ "http\:\/\/example\.me\/" [R=301,L]

Below you can check the full correct .htaccess file

<IfModule mod_rewrite.c>

RewriteEngine On

SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots

RewriteCond %{HTTP_USER_AGENT} libwww [NC,OR]

RewriteCond %{QUERY_STRING} ^(.*)=http [NC]

RewriteRule ^(.*)$ – [F,L]

RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^/?$ "http\:\/\/example\.me\/" [R=301,L]

# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0

# Set up caching on media files for 1 month
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A2419200
Header append Cache-Control "public"
</FilesMatch>

# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>

# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive On
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>

</IfModule>
Marcell Almeida
  • 292
  • 3
  • 9