Strange problem with RewriteCond

MultiformeIngegno

  • Posts: 1,337
Strange problem with RewriteCond
« on January 8th, 2012, 12:50 AM »
I'm using this cond to redirect my forum.domain.com subdomain to domain.com/forum folder:
Code: [Select]
RewriteCond %{HTTP_HOST} ^[www\.]*forum.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

Everything works fine, except for Aeva links.. for example I have this image:
Code: [Select]
http://forum.domain.com/index.php?action=media;sa=media;in=252;thumb

Instead of:
Code: [Select]
http://domain.com/forum/index.php?action=media;sa=media;in=252;thumb

it gets redirected to:
Code: [Select]
http://domain.com/forum/index.php?action=media%3bsa=media%3bin=252%3bthumb

So I get a 404 error.. seems like a char-set problem!

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Strange problem with RewriteCond
« Reply #1, on January 8th, 2012, 01:15 AM »
No, not a charset problem. Apache is doing what it's supposed to be doing, rewriting %3b characters as per the HTTP specification.

Try:
Code: [Select]
RewriteRule ^(.*)$ http://domain.com/$1 [NE,R=301,L]
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

MultiformeIngegno

  • Posts: 1,337

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Strange problem with RewriteCond
« Reply #3, on January 8th, 2012, 01:29 AM »
I've done my fair share of fighting with RewriteRules in the past, I'm trying to give it up, it's like smoking: you kind of enjoy it even though you know it's bad for you.

MultiformeIngegno

  • Posts: 1,337
Re: Strange problem with RewriteCond
« Reply #4, on January 8th, 2012, 01:49 AM »
Ahaha!
Anyway I'm ditching many rewritcond I had because there are other ways to achive some things. For example I had a rewrite rule that redirected all www hits to the non-www url. I just left the domain.com A record, removed the www one and replaced it with a CNAME (from www to the "pure" @ domain). I think it's more clean.

Nao

  • Dadman with a boy
  • Posts: 16,082

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Strange problem with RewriteCond
« Reply #6, on January 8th, 2012, 01:52 PM »
Quote from MultiformeIngegno on January 8th, 2012, 01:49 AM
Ahaha!
Anyway I'm ditching many rewritcond I had because there are other ways to achive some things. For example I had a rewrite rule that redirected all www hits to the non-www url. I just left the domain.com A record, removed the www one and replaced it with a CNAME (from www to the "pure" @ domain). I think it's more clean.
That can work but it has other consequences, most notably that you will have 'duplicate' content because both www. and non www. links will point to the same content. Having a forced redirect solves that.
Quote from Nao on January 8th, 2012, 08:47 AM
Are you a smoker, Pete?
Nope, but both my parents, both step parents, all my aunts/uncles on mother's side, plus my maternal grandparents, plus half my dad's family (including maternal grandmother) all smoke(d)[1]

It's more the fact that I understand the psychology, it's pretty similar to when I gave up alcohol for the most part some years ago (I still have the odd drink, but it's once every few months, and even then, it's invariably just the one, two for really special occasions)
 1. Past tense as some of them gave up. Many of them didn't, however.

MultiformeIngegno

  • Posts: 1,337
Re: Strange problem with RewriteCond
« Reply #7, on January 8th, 2012, 02:56 PM »
D'oh.. I thought that CNAME "redirection" solved the problem of duplicate content... because when you visit www.domain.com you are physically redirected to domain.com. Don't search engines follow this behavior and consider only non www content? Also because the www subdomain doesn't exist in reality (if you search for A records you get none)..
Re: Strange problem with RewriteCond
« Reply #8, on January 8th, 2012, 03:04 PM »
Anyway if I add a 301 redirect from www to non-www I should "restore" the A record for the www entry, right? It wouldn't work if I had a CNAME record for www (because hits get redirected before "reading" the .htacces)? :)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Strange problem with RewriteCond
« Reply #9, on January 8th, 2012, 03:49 PM »
No, CNAME means canonical name, it doesn't perform redirection. The whole point of CNAMEs is to provide multiple pathways to the same destination.

The rest of the code on your site might be doing that redirection, however, and I know SMF has internal handling to shunt users to the proper domain.

If you add a 301, you should indeed restore the A record and deal with the redirection on the server yourself, it's the only way to be sure.

MultiformeIngegno

  • Posts: 1,337
Re: Strange problem with RewriteCond
« Reply #10, on January 8th, 2012, 04:08 PM »
'kay! Restored A entry. :whistle:
Now, because you are a genius.. you can explain me WTF does this code do (in .htaccess).. :hmm:

Code: [Select]
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</Files>

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Strange problem with RewriteCond
« Reply #11, on January 8th, 2012, 04:14 PM »
That code checks for anyone requesting files that begin with .hta (like .htaccess) and blocks the request entirely. Though that shouldn't be necessary in an .htaccess file because the stock Apache configuration expressly denies that at the highest level.

Oracle

  • Posts: 78