Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm losing my mind here.

I had a .htaccess for a website with the following content:

Options FollowSymLinks
<ifmodule mod_rewrite.c>
RewriteEngine on
rewritecond %{http_host} ^XXX.com.ar [nc]
rewriterule ^(.*)$ http://www.XXX.com.ar/$1 [r=301,nc] 
</ifmodule>

It just added the "www" prior the URL if the user had not written it.

After doing some development, I made a simple "Router" framework for my site. Then, every request had to go to index.php and it "dispatches" it. So, my .htaccess ended like this:

Options FollowSymLinks
<ifmodule mod_rewrite.c>
RewriteEngine on
rewritecond %{http_host} ^XXX.com.ar [nc]
rewriterule ^(.*)$ http://www.XXX.com.ar/$1 [r=301,nc] 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ../index.php?url=$1 [NC,L]
</ifmodule>

The problem is that now, when I go to: XXX.com.ar (without the www) I have a 301 - Moved Permanently

301 - Moved Permanently > 301 - Moved Permanently301 - Moved Permanently

message.

And something like this (in the same document):

ErrorDocument to handle the request.

ErrorDocument to handle the request.> Additionally, a 400 Bad Request error

was encountered while trying to use an ErrorDocument to handle the request.ErrorDocument to handle the request.

301 - Moved Permanently ErrorDocument to handle the request.

share|improve this question
1  
Quick sanity check, why do you have [r=301,nc] in your 1st rewrite rule, specifically "nc" - shouldn't that be [R=301,L]? –  PP. Oct 5 '10 at 14:03

2 Answers 2

Try:

RewriteEngine on
RewriteCond %{HTTP_HOST} XXX.com.ar [NC]
RewriteRule ^(.*)$ http://www.XXX.com.ar/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
share|improve this answer
    
No, it doesn't work! Gives me a 500 - Internal Server Error. And when the host is reached without the www, it still shows the same error (301) –  santiago.basulto Oct 5 '10 at 15:35
    
I've solved it. Just move the %{HTTP_HOST}... to the bottom. Thanks! –  santiago.basulto Oct 5 '10 at 15:46
up vote 0 down vote accepted

Just changed the places of the sentences and works well

Options FollowSymLinks
<ifmodule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ../index.php?url=$1 [NC,L]
rewritecond %{http_host} ^XXX.com.ar [nc]
rewriterule ^(.*)$ http://www.XXX.com.ar/$1 [r=301,nc] 
</ifmodule>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.