0

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.

1
  • 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
1

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]
2
  • 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) Oct 5 '10 at 15:35
  • I've solved it. Just move the %{HTTP_HOST}... to the bottom. Thanks! Oct 5 '10 at 15:46
0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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